OLD | NEW |
---|---|
(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 "chrome/browser/extensions/api/push_messaging/push_messaging_api.h" | |
6 | |
7 #include "base/bind.h" | |
8 #include "base/json/json_writer.h" | |
9 #include "base/values.h" | |
10 #include "chrome/browser/extensions/event_router.h" | |
11 #include "chrome/browser/profiles/profile.h" | |
12 #include "content/public/browser/browser_thread.h" | |
13 #include "googleurl/src/gurl.h" | |
14 | |
15 using content::BrowserThread; | |
16 | |
17 namespace extensions { | |
18 | |
19 namespace { | |
20 const char kEventName[] = "experimental.pushMessaging.onMessage"; | |
21 // Keys for JSON dictionary for the onMessage event. | |
22 const char kPayloadKey[] = "payload"; | |
Mihai Parparita -not on Chrome
2012/08/01 20:05:50
The extensions infrastructure now supports auto-ge
dcheng
2012/08/01 21:15:33
Done. This is really neat!
| |
23 const char kSubchannelKey[] = "subchannel"; | |
24 } // namespace | |
25 | |
26 ExtensionPushMessagingEventRouter::ExtensionPushMessagingEventRouter( | |
27 Profile* profile) | |
28 : profile_(profile) { | |
29 } | |
30 | |
31 ExtensionPushMessagingEventRouter::~ExtensionPushMessagingEventRouter() {} | |
32 | |
33 void ExtensionPushMessagingEventRouter::Init() { | |
34 // TODO(dcheng): Add hooks into InvalidationHandler when landed. | |
35 } | |
36 | |
37 void ExtensionPushMessagingEventRouter::OnMessage( | |
38 const std::string& extension_id, | |
39 int subchannel, | |
40 const std::string& payload) { | |
41 DictionaryValue* dict = new DictionaryValue; | |
42 dict->SetInteger(kSubchannelKey, subchannel); | |
43 dict->SetString(kPayloadKey, payload); | |
44 | |
45 ListValue args; | |
46 args.Append(dict); | |
47 std::string json_args; | |
48 base::JSONWriter::Write(&args, &json_args); | |
49 | |
50 profile_->GetExtensionEventRouter()->DispatchEventToExtension( | |
51 extension_id, | |
52 kEventName, | |
53 json_args, | |
54 profile_, | |
55 GURL()); | |
56 } | |
57 | |
58 } // namespace extensions | |
OLD | NEW |