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

Unified Diff: chrome/browser/extensions/web_intent_callbacks.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/web_intent_callbacks.cc
diff --git a/chrome/browser/extensions/web_intent_callbacks.cc b/chrome/browser/extensions/web_intent_callbacks.cc
new file mode 100644
index 0000000000000000000000000000000000000000..c8d6264eb140b96574b597b87371d7acefd7ec5c
--- /dev/null
+++ b/chrome/browser/extensions/web_intent_callbacks.cc
@@ -0,0 +1,99 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/bind.h"
+#include "base/stringprintf.h"
+#include "chrome/browser/extensions/web_intent_callbacks.h"
+#include "chrome/browser/profiles/profile_dependency_manager.h"
+#include "chrome/common/extensions/extension.h"
+#include "content/public/browser/web_contents.h"
+#include "content/public/browser/web_contents_observer.h"
+#include "content/public/browser/web_intents_dispatcher.h"
+#include "webkit/glue/web_intent_reply_data.h"
+
+namespace {
+
+// Get the key for use in the internal pending WebIntentCallback map.
+std::string GetKey(const extensions::Extension* extension, int id) {
+ return StringPrintf("%s/%d", extension->id().c_str(), id);
+}
+
+} // namespace
+
+namespace extensions {
+
+WebIntentCallbacks::WebIntentCallbacks() {}
+
+WebIntentCallbacks::~WebIntentCallbacks() {}
+
+// static
+WebIntentCallbacks* WebIntentCallbacks::Get(Profile* profile) {
+ return Factory::GetForProfile(profile);
+}
+
+int WebIntentCallbacks::RegisterCallback(
+ const Extension* extension, content::WebIntentsDispatcher* dispatcher) {
+ int id = last_id_++;
+ std::string key = GetKey(extension, id);
+ pending_[key] = dispatcher;
+
+ LOG(INFO) << "Storing callback for intent with key=" << key;
+
+ // TODO(thorogood): We don't listen to the lifecycle of the platform app that
+ // handles this intent.
+ // This listens to when the platform app makes a reply, or when the caller
+ // page is destroyed (calls us with WEB_INTENT_SERVICE_CONTENTS_CLOSED).
+ dispatcher->RegisterReplyNotification(
+ base::Bind(&WebIntentCallbacks::OnIntentReply, base::Unretained(this), key));
+ return id;
+}
+
+content::WebIntentsDispatcher* WebIntentCallbacks::RetrieveCallback(
+ const Extension* extension, int id) {
+ std::string key = GetKey(extension, id);
+
+ if (pending_.count(key))
+ return pending_[key];
+
+ return NULL;
+}
+
+void WebIntentCallbacks::OnIntentReply(
+ std::string key,
+ webkit_glue::WebIntentReplyType reply_type) {
+ // TODO(thorogood): We should be seeing WEB_INTENT_SERVICE_CONTENTS_CLOSED here.
+ // This should be getting run by intents_dispatcher.cc:42.
+
+ LOG(INFO) << "Intent with key=" << key << " being replied, clearing it, count=" << (int) pending_.count(key);
+ pending_.erase(key);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// Factory boilerplate
+
+// static
+WebIntentCallbacks* WebIntentCallbacks::Factory::GetForProfile(
+ Profile* profile) {
+ return static_cast<WebIntentCallbacks*>(
+ GetInstance()->GetServiceForProfile(profile, true));
+}
+
+WebIntentCallbacks::Factory* WebIntentCallbacks::Factory::GetInstance() {
+ return Singleton<WebIntentCallbacks::Factory>::get();
+}
+
+WebIntentCallbacks::Factory::Factory()
+ : ProfileKeyedServiceFactory("WebIntentCallbacks",
+ ProfileDependencyManager::GetInstance()) {
+}
+
+WebIntentCallbacks::Factory::~Factory() {
+}
+
+ProfileKeyedService* WebIntentCallbacks::Factory::BuildServiceInstanceFor(
+ Profile* profile) const {
+ return new WebIntentCallbacks();
+}
+
+} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698