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

Unified Diff: chrome/browser/extensions/api/app_runtime/app_runtime_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: about to submit Created 8 years, 3 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_runtime/app_runtime_api.cc
diff --git a/chrome/browser/extensions/api/app_runtime/app_runtime_api.cc b/chrome/browser/extensions/api/app_runtime/app_runtime_api.cc
index 614dfe1e4de7d7bacbe1d403b98fff0e06cc8fee..5527bcdc8581ec37638385a839d403207d876016 100644
--- a/chrome/browser/extensions/api/app_runtime/app_runtime_api.cc
+++ b/chrome/browser/extensions/api/app_runtime/app_runtime_api.cc
@@ -10,15 +10,24 @@
#include "base/utf_string_conversions.h"
#include "base/values.h"
#include "chrome/browser/extensions/event_router.h"
+#include "chrome/browser/extensions/web_intent_callbacks.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/extensions/extension.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"
namespace {
+const char kIntentIdKey[] = "intentId";
+const char kIntentSuccessKey[] = "success";
+const char kIntentDataKey[] = "data";
const char kOnLaunchedEvent[] = "app.runtime.onLaunched";
+const char kCallbackNotFoundError[] =
+ "WebIntent callback not found; perhaps already responded to";
+
} // anonymous namespace
namespace extensions {
@@ -56,7 +65,9 @@ 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();
scoped_ptr<ListValue> args(new ListValue());
DictionaryValue* launch_data = new DictionaryValue();
DictionaryValue* intent = new DictionaryValue();
@@ -75,6 +86,7 @@ void AppEventRouter::DispatchOnLaunchedEventWithWebIntent(
args->Append(intent_data);
break;
case webkit_glue::WebIntentData::UNSERIALIZED:
+ args->Append(Value::CreateNullValue());
intent->SetString("data", UTF16ToUTF8(web_intent_data.unserialized_data));
break;
case webkit_glue::WebIntentData::BLOB:
@@ -98,8 +110,42 @@ void AppEventRouter::DispatchOnLaunchedEventWithWebIntent(
NOTREACHED();
break;
}
+ DCHECK(args->GetSize() == 2); // intent_id must be our third argument.
+ WebIntentCallbacks* callbacks = WebIntentCallbacks::Get(profile);
+ int intent_id =
+ callbacks->RegisterCallback(extension, intents_dispatcher, source);
+ args->Append(base::Value::CreateIntegerValue(intent_id));
profile->GetExtensionEventRouter()->DispatchEventToExtension(
extension->id(), kOnLaunchedEvent, args.Pass(), NULL, GURL());
}
+bool AppRuntimePostIntentResponseFunction::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;
+}
+
} // namespace extensions
« no previous file with comments | « chrome/browser/extensions/api/app_runtime/app_runtime_api.h ('k') | chrome/browser/extensions/platform_app_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698