Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(750)

Unified Diff: chrome/browser/extensions/api/app/app_api.cc

Issue 10828172: Allow platform apps to respond to Web Intents (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: comments Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 22ccab68a4cb7ae663f60c773569eed38751ca7a..1dcbb67f2900e75e7b4748d2be7e888f210df79f 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,36 @@ bool AppClearAllNotificationsFunction::RunImpl() {
return true;
}
+bool PostIntentResponseFunction::RunImpl() {
+ DictionaryValue* details;
koz (OOO until 15th September) 2012/08/13 00:29:40 nit: initialize to NULL.
thorogood 2012/08/13 05:00:12 Done.
+ EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &details));
+ EXTENSION_FUNCTION_VALIDATE(details != NULL);
koz (OOO until 15th September) 2012/08/13 00:29:40 I think this case is handled by the previous line,
thorogood 2012/08/13 05:00:12 Done.
+
+ int intent_id;
+ EXTENSION_FUNCTION_VALIDATE(details->GetInteger(kIntentIdKey, &intent_id));
+
+ WebIntentCallbacks* callbacks = WebIntentCallbacks::Get(profile());
+ content::WebIntentsDispatcher* intents_dispatcher =
+ callbacks->RetrieveCallback(GetExtension(), 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));
+
+ intents_dispatcher->SendReplyMessage(reply_type, UTF8ToUTF16(data));
+ return true;
+}
+
// static.
void AppEventRouter::DispatchOnLaunchedEvent(
Profile* profile, const Extension* extension) {
@@ -149,8 +185,14 @@ 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);
+ int intent_id = callbacks->RegisterCallback(extension, intents_dispatcher);
+
scoped_ptr<ListValue> args(new ListValue());
+ args->Append(base::Value::CreateIntegerValue(intent_id));
+
DictionaryValue* launch_data = new DictionaryValue();
DictionaryValue* intent = new DictionaryValue();
intent->SetString("action", UTF16ToUTF8(web_intent_data.action));

Powered by Google App Engine
This is Rietveld 408576698