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

Side by Side Diff: chrome/browser/extensions/api/rtc_private/rtc_private_api.cc

Issue 10919086: Wired chrome.rtcPrivate API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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 unified diff | Download patch | Annotate | Revision Log
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 "chrome/browser/extensions/api/rtc_private/rtc_private_api.h"
6
7 #include "base/json/json_writer.h"
8 #include "base/message_loop.h"
9 #include "base/stringprintf.h"
10 #include "base/time.h"
11 #include "base/utf_string_conversions.h"
12 #include "base/value_conversions.h"
13 #include "base/values.h"
14 #include "chrome/browser/chromeos/contacts/contact_manager.h"
15 #include "chrome/browser/chromeos/contacts/contact.pb.h"
16 #include "chrome/browser/extensions/event_router.h"
17 #include "chrome/browser/extensions/extension_service.h"
18 #include "chrome/browser/extensions/extension_system.h"
19 #include "chrome/browser/extensions/state_store.h"
20 #include "chrome/browser/profiles/profile.h"
21 #include "chrome/common/chrome_notification_types.h"
22 #include "chrome/common/extensions/api/rtc_private.h"
23 #include "content/public/browser/notification_service.h"
24
25 using base::DictionaryValue;
26 using base::ListValue;
27 using base::Value;
28 using contacts::Contact;
29 using contacts::Contact_EmailAddress;
30 using contacts::Contact_PhoneNumber;
31
32 namespace extensions {
33
34 namespace {
35
36 // Launch event name.
37 const char kOnLaunchEvent[] = "rtcPrivate.onLaunch";
38 // Default RTC extension id.
39 const char kDefaultRtcExtensionId[] = "ljclpkphhpbpinifbeabbhlfddcpfdde";
Dmitry Titov 2012/09/05 21:47:47 This seems not used.
zel 2012/09/05 22:06:21 Done.
40 // Web intent data payload mimetype.
41 const char kMimeTypeJson[] = "application/json";
42 // Web intent actions.
43 const char kActivateAction[] = "activate";
44 const char kChatAction[] = "chat";
45 const char kVoiceAction[] = "voice";
46 const char kVideoAction[] = "video";
47 // Web intent data structure fields.
48 const char kNameIntentField[] = "name";
49 const char kPhoneIntentField[] = "phone";
50 const char kEmailIntentField[] = "email";
51
52 // Returns string representation of intent action.
53 const char* GetLaunchAction(RtcPrivateApi::LaunchAction action) {
54 const char* action_str = kActivateAction;
55 switch (action) {
56 case RtcPrivateApi::LAUNCH_ACTIVATE:
57 action_str = kActivateAction;
58 break;
59 case RtcPrivateApi::LAUNCH_CHAT:
60 action_str = kChatAction;
61 break;
62 case RtcPrivateApi::LAUNCH_VOICE:
63 action_str = kVoiceAction;
64 break;
65 case RtcPrivateApi::LAUNCH_VIDEO:
66 action_str = kVideoAction;
67 break;
68 default:
69 NOTREACHED() << "Unknown action " << action;
70 break;
71 }
72 return action_str;
73 }
74
75 // Creates JSON payload string for contact web intent data.
76 std::string GetContactIntentData(Contact* contact) {
Mihai Parparita -not on Chrome 2012/09/05 22:01:10 Does this have to be a string? Normally intent dat
zel 2012/09/05 22:28:26 Done.
77 base::DictionaryValue dict;
78
79 // TODO(derat): This might require more name extraction magic than this.
80 dict.SetString(kNameIntentField, contact->full_name());
81
82 ListValue* phone_list = new base::ListValue();
83 dict.Set(kPhoneIntentField, phone_list);
84 for (int i = 0; i < contact->phone_numbers_size(); i++) {
85 const Contact_PhoneNumber& phone_number = contact->phone_numbers(i);
86 StringValue* value = Value::CreateStringValue(phone_number.number());
87 if (phone_number.primary())
88 CHECK(phone_list->Insert(0, value));
89 else
90 phone_list->Append(value);
91 }
92
93 ListValue* email_list = new base::ListValue();
94 dict.Set(kPhoneIntentField, email_list);
95 for (int i = 0; i < contact->email_addresses_size(); i++) {
96 const Contact_EmailAddress& email_address = contact->email_addresses(i);
97 StringValue* value = Value::CreateStringValue(email_address.address());
98 if (email_address.primary())
99 CHECK(email_list->Insert(0, value));
100 else
101 email_list->Append(value);
102 }
103
104 std::string data;
105 base::JSONWriter::Write(&dict, &data);
106 return data;
107 }
108
109
110 } // namespace
111
112
113 void RtcPrivateApi::RaiseLaunchEvent(Profile* profile,
114 LaunchAction action,
115 Contact* contact) {
116 if (action == RtcPrivateApi::LAUNCH_ACTIVATE) {
117 extensions::ExtensionSystem::Get(profile)->event_router()->
118 DispatchEventToRenderers(
119 kOnLaunchEvent,
120 scoped_ptr<ListValue>(new ListValue()),
121 profile,
122 GURL());
123 } else {
124 extensions::api::rtc_private::LaunchData launch_data;
125 launch_data.intent.action = GetLaunchAction(action);
126 launch_data.intent.data = GetContactIntentData(contact);
127 launch_data.intent.type = kMimeTypeJson;
128 extensions::ExtensionSystem::Get(profile)->event_router()->
129 DispatchEventToRenderers(
130 kOnLaunchEvent,
131 extensions::api::rtc_private::OnLaunch::Create(launch_data),
132 profile,
133 GURL());
134 }
135 }
136
137 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698