Chromium Code Reviews| Index: chrome/browser/extensions/api/app/app_api.cc |
| diff --git a/chrome/browser/extensions/api/app/app_api.cc b/chrome/browser/extensions/api/app/app_api.cc |
| index ff4e2aa0c1e6897ccd0b3b07fe421fd7a2dc6dc9..0cf7d03240aa2891b520faea3249144301ca45a2 100644 |
| --- a/chrome/browser/extensions/api/app/app_api.cc |
| +++ b/chrome/browser/extensions/api/app/app_api.cc |
| @@ -12,11 +12,13 @@ |
| #include "chrome/browser/extensions/app_notification_manager.h" |
| #include "chrome/browser/extensions/event_router.h" |
| #include "chrome/browser/extensions/extension_service.h" |
| +#include "chrome/browser/extensions/web_intent_callbacks.h" |
| #include "chrome/browser/profiles/profile.h" |
| #include "chrome/common/chrome_notification_types.h" |
| #include "chrome/common/extensions/extension.h" |
| #include "chrome/common/extensions/extension_constants.h" |
| #include "content/public/browser/notification_service.h" |
| +#include "content/public/browser/web_intents_dispatcher.h" |
| #include "googleurl/src/gurl.h" |
| #include "webkit/glue/web_intent_data.h" |
| @@ -27,13 +29,17 @@ const char kExtensionIdKey[] = "extensionId"; |
| const char kLinkTextKey[] = "linkText"; |
| const char kLinkUrlKey[] = "linkUrl"; |
| const char kTitleKey[] = "title"; |
| +const char kIntentIdKey[] = "intentId"; |
| +const char kIntentSuccessKey[] = "success"; |
| +const char kIntentDataKey[] = "data"; |
| const char kInvalidExtensionIdError[] = |
| "Invalid extension id"; |
| const char kMissingLinkTextError[] = |
| "You must specify linkText if you use linkUrl"; |
| +const char kCallbackNotFoundError[] = |
| + "WebIntent callback not found; perhaps already responded to"; |
| const char kOnLaunchedEvent[] = "experimental.app.onLaunched"; |
| - |
| } // anonymous namespace |
| namespace extensions { |
| @@ -118,6 +124,50 @@ bool AppClearAllNotificationsFunction::RunImpl() { |
| return true; |
| } |
| +bool PostIntentResponseFunction::RunImpl() { |
| + DictionaryValue* details; |
| + EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &details)); |
| + EXTENSION_FUNCTION_VALIDATE(details != NULL); |
| + |
| + std::string intent_id; |
| + if (details->HasKey(kIntentIdKey)) |
|
koz (OOO until 15th September)
2012/08/08 04:47:30
Is this not always present?
thorogood
2012/08/08 07:15:49
I've removed the HasKey checks, since yes, EXTENSI
|
| + EXTENSION_FUNCTION_VALIDATE(details->GetString(kIntentIdKey, &intent_id)); |
| + |
| + WebIntentCallbacks* callbacks = WebIntentCallbacks::Get(profile()); |
| + content::WebIntentsDispatcher* intents_dispatcher = |
| + callbacks->RetrieveCallback(intent_id); |
| + if (!intents_dispatcher) { |
| + error_ = kCallbackNotFoundError; |
| + return false; |
| + } |
| + |
| + webkit_glue::WebIntentReplyType reply_type = |
| + webkit_glue::WEB_INTENT_REPLY_FAILURE; |
| + if (details->HasKey(kIntentSuccessKey)) { |
| + bool success; |
| + EXTENSION_FUNCTION_VALIDATE( |
| + details->GetBoolean(kIntentSuccessKey, &success)); |
| + if (success) |
| + reply_type = webkit_glue::WEB_INTENT_REPLY_SUCCESS; |
| + } |
| + |
| + Value* result; |
|
koz (OOO until 15th September)
2012/08/08 04:47:30
Initialize to NULL.
thorogood
2012/08/08 07:15:49
No longer relevant, as now I'm using a std::string
|
| + if (details->HasKey(kIntentDataKey)) |
| + EXTENSION_FUNCTION_VALIDATE(details->Get(kIntentDataKey, &result)); |
| + else |
| + result = Value::CreateNullValue(); // TODO: need to free this |
| + std::string json_args; |
| + base::JSONWriter::Write(result, &json_args); |
| + |
| + LOG(INFO) << "PostIntentResponseFunction(), intent_id=" << intent_id |
| + << ", success=" << (reply_type == webkit_glue::WEB_INTENT_REPLY_SUCCESS) |
| + << ", data=``" << json_args << "``"; |
| + |
| + // NOTE: The original intent callback only seems to receive "NULL". |
| + intents_dispatcher->SendReplyMessage(reply_type, UTF8ToUTF16(json_args)); |
| + return true; |
| +} |
| + |
| // static. |
| void AppEventRouter::DispatchOnLaunchedEvent( |
| Profile* profile, const Extension* extension) { |
| @@ -127,8 +177,9 @@ void AppEventRouter::DispatchOnLaunchedEvent( |
| // static. |
| void AppEventRouter::DispatchOnLaunchedEventWithFileEntry( |
| - Profile* profile, const Extension* extension, const string16& action, |
| - const std::string& file_system_id, const std::string& base_name) { |
| + Profile* profile, const Extension* extension, |
| + const string16& action, const std::string& file_system_id, |
| + const std::string& base_name) { |
| ListValue args; |
| DictionaryValue* launch_data = new DictionaryValue(); |
| DictionaryValue* intent = new DictionaryValue(); |
| @@ -150,8 +201,13 @@ void AppEventRouter::DispatchOnLaunchedEventWithFileEntry( |
| // static. |
| void AppEventRouter::DispatchOnLaunchedEventWithWebIntent( |
| Profile* profile, const Extension* extension, |
| - const webkit_glue::WebIntentData web_intent_data) { |
| + content::WebIntentsDispatcher* intents_dispatcher) { |
| + webkit_glue::WebIntentData web_intent_data = intents_dispatcher->GetIntent(); |
| + WebIntentCallbacks* callbacks = WebIntentCallbacks::Get(profile); |
| + std::string intent_id = callbacks->RegisterCallback(intents_dispatcher); |
| + |
| ListValue args; |
| + args.Append(base::Value::CreateStringValue(intent_id)); |
| DictionaryValue* launch_data = new DictionaryValue(); |
| DictionaryValue* intent = new DictionaryValue(); |
| intent->SetString("action", UTF16ToUTF8(web_intent_data.action)); |