| 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..4bff8f475343e51211907b237a579411e11ab83a 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,40 @@ 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;
|
| + 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;
|
| + bool success;
|
| + EXTENSION_FUNCTION_VALIDATE(details->GetBoolean(kIntentSuccessKey, &success));
|
| + if (success)
|
| + reply_type = webkit_glue::WEB_INTENT_REPLY_SUCCESS;
|
| +
|
| + std::string data;
|
| + EXTENSION_FUNCTION_VALIDATE(details->GetString(kIntentDataKey, &data));
|
| +
|
| + LOG(INFO) << "PostIntentResponseFunction(), intent_id=" << intent_id
|
| + << ", success=" << (reply_type == webkit_glue::WEB_INTENT_REPLY_SUCCESS)
|
| + << ", data=``" << data << "``";
|
| +
|
| + intents_dispatcher->SendReplyMessage(reply_type, UTF8ToUTF16(data));
|
| + return true;
|
| +}
|
| +
|
| // static.
|
| void AppEventRouter::DispatchOnLaunchedEvent(
|
| Profile* profile, const Extension* extension) {
|
| @@ -127,8 +167,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 +191,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));
|
|
|