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

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: Ben' 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..df1669ac6c8945ac0bf95a63836c9f48ff846b5c 100644
--- a/chrome/browser/extensions/api/app/app_api.cc
+++ b/chrome/browser/extensions/api/app/app_api.cc
@@ -12,11 +12,14 @@
#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_contents.h"
+#include "content/public/browser/web_intents_dispatcher.h"
#include "googleurl/src/gurl.h"
#include "webkit/glue/web_intent_data.h"
@@ -27,11 +30,16 @@ 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
@@ -118,6 +126,35 @@ bool AppClearAllNotificationsFunction::RunImpl() {
return true;
}
+bool PostIntentResponseFunction::RunImpl() {
+ DictionaryValue* details = NULL;
+ EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &details));
+
+ int intent_id = 0;
+ 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) {
@@ -131,6 +168,7 @@ void AppEventRouter::DispatchOnLaunchedEventWithFileEntry(
Profile* profile, const Extension* extension, const string16& action,
const std::string& file_system_id, const std::string& base_name) {
scoped_ptr<ListValue> args(new ListValue());
+ args->Append(base::Value::CreateIntegerValue(0)); // no intent ID
DictionaryValue* launch_data = new DictionaryValue();
DictionaryValue* intent = new DictionaryValue();
intent->SetString("action", UTF16ToUTF8(action));
@@ -149,8 +187,16 @@ void AppEventRouter::DispatchOnLaunchedEventWithFileEntry(
// static.
void AppEventRouter::DispatchOnLaunchedEventWithWebIntent(
Profile* profile, const Extension* extension,
- const webkit_glue::WebIntentData web_intent_data) {
+ content::WebIntentsDispatcher* intents_dispatcher,
+ content::WebContents* source) {
+ webkit_glue::WebIntentData web_intent_data = intents_dispatcher->GetIntent();
+ WebIntentCallbacks* callbacks = WebIntentCallbacks::Get(profile);
+ int intent_id =
+ callbacks->RegisterCallback(extension, intents_dispatcher, source);
+
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