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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/bind.h"
6 #include "base/stringprintf.h"
7 #include "chrome/browser/extensions/web_intent_callbacks.h"
8 #include "chrome/browser/profiles/profile_dependency_manager.h"
9 #include "chrome/common/extensions/extension.h"
10 #include "content/public/browser/web_contents.h"
11 #include "content/public/browser/web_contents_observer.h"
12 #include "content/public/browser/web_intents_dispatcher.h"
13 #include "webkit/glue/web_intent_reply_data.h"
14
15 namespace {
16
17 // Get the key for use in the internal pending WebIntentCallback map.
18 std::string GetKey(const extensions::Extension* extension, int id) {
19 return StringPrintf("%s/%d", extension->id().c_str(), id);
20 }
21
22 } // namespace
23
24 namespace extensions {
25
26 WebIntentCallbacks::WebIntentCallbacks() {}
27
28 WebIntentCallbacks::~WebIntentCallbacks() {}
29
30 // static
31 WebIntentCallbacks* WebIntentCallbacks::Get(Profile* profile) {
32 return Factory::GetForProfile(profile);
33 }
34
35 int WebIntentCallbacks::RegisterCallback(
36 const Extension* extension, content::WebIntentsDispatcher* dispatcher) {
37 int id = last_id_++;
38 std::string key = GetKey(extension, id);
39 pending_[key] = dispatcher;
40
41 LOG(INFO) << "Storing callback for intent with key=" << key;
42
43 // TODO(thorogood): We don't listen to the lifecycle of the platform app that
44 // handles this intent.
45 // This listens to when the platform app makes a reply, or when the caller
46 // page is destroyed (calls us with WEB_INTENT_SERVICE_CONTENTS_CLOSED).
47 dispatcher->RegisterReplyNotification(
48 base::Bind(&WebIntentCallbacks::OnIntentReply, base::Unretained(this), key ));
49 return id;
50 }
51
52 content::WebIntentsDispatcher* WebIntentCallbacks::RetrieveCallback(
53 const Extension* extension, int id) {
54 std::string key = GetKey(extension, id);
55
56 if (pending_.count(key))
57 return pending_[key];
58
59 return NULL;
60 }
61
62 void WebIntentCallbacks::OnIntentReply(
63 std::string key,
64 webkit_glue::WebIntentReplyType reply_type) {
65 // TODO(thorogood): We should be seeing WEB_INTENT_SERVICE_CONTENTS_CLOSED her e.
66 // This should be getting run by intents_dispatcher.cc:42.
67
68 LOG(INFO) << "Intent with key=" << key << " being replied, clearing it, count= " << (int) pending_.count(key);
69 pending_.erase(key);
70 }
71
72 ///////////////////////////////////////////////////////////////////////////////
73 // Factory boilerplate
74
75 // static
76 WebIntentCallbacks* WebIntentCallbacks::Factory::GetForProfile(
77 Profile* profile) {
78 return static_cast<WebIntentCallbacks*>(
79 GetInstance()->GetServiceForProfile(profile, true));
80 }
81
82 WebIntentCallbacks::Factory* WebIntentCallbacks::Factory::GetInstance() {
83 return Singleton<WebIntentCallbacks::Factory>::get();
84 }
85
86 WebIntentCallbacks::Factory::Factory()
87 : ProfileKeyedServiceFactory("WebIntentCallbacks",
88 ProfileDependencyManager::GetInstance()) {
89 }
90
91 WebIntentCallbacks::Factory::~Factory() {
92 }
93
94 ProfileKeyedService* WebIntentCallbacks::Factory::BuildServiceInstanceFor(
95 Profile* profile) const {
96 return new WebIntentCallbacks();
97 }
98
99 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698