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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/api/rtc_private/rtc_private_api.cc
diff --git a/chrome/browser/extensions/api/rtc_private/rtc_private_api.cc b/chrome/browser/extensions/api/rtc_private/rtc_private_api.cc
new file mode 100644
index 0000000000000000000000000000000000000000..8338f74e136d62e5e9a2ba35e24267ed5b2aea59
--- /dev/null
+++ b/chrome/browser/extensions/api/rtc_private/rtc_private_api.cc
@@ -0,0 +1,137 @@
+// 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 "chrome/browser/extensions/api/rtc_private/rtc_private_api.h"
+
+#include "base/json/json_writer.h"
+#include "base/message_loop.h"
+#include "base/stringprintf.h"
+#include "base/time.h"
+#include "base/utf_string_conversions.h"
+#include "base/value_conversions.h"
+#include "base/values.h"
+#include "chrome/browser/chromeos/contacts/contact_manager.h"
+#include "chrome/browser/chromeos/contacts/contact.pb.h"
+#include "chrome/browser/extensions/event_router.h"
+#include "chrome/browser/extensions/extension_service.h"
+#include "chrome/browser/extensions/extension_system.h"
+#include "chrome/browser/extensions/state_store.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/common/chrome_notification_types.h"
+#include "chrome/common/extensions/api/rtc_private.h"
+#include "content/public/browser/notification_service.h"
+
+using base::DictionaryValue;
+using base::ListValue;
+using base::Value;
+using contacts::Contact;
+using contacts::Contact_EmailAddress;
+using contacts::Contact_PhoneNumber;
+
+namespace extensions {
+
+namespace {
+
+// Launch event name.
+const char kOnLaunchEvent[] = "rtcPrivate.onLaunch";
+// Default RTC extension id.
+const char kDefaultRtcExtensionId[] = "ljclpkphhpbpinifbeabbhlfddcpfdde";
Dmitry Titov 2012/09/05 21:47:47 This seems not used.
zel 2012/09/05 22:06:21 Done.
+// Web intent data payload mimetype.
+const char kMimeTypeJson[] = "application/json";
+// Web intent actions.
+const char kActivateAction[] = "activate";
+const char kChatAction[] = "chat";
+const char kVoiceAction[] = "voice";
+const char kVideoAction[] = "video";
+// Web intent data structure fields.
+const char kNameIntentField[] = "name";
+const char kPhoneIntentField[] = "phone";
+const char kEmailIntentField[] = "email";
+
+// Returns string representation of intent action.
+const char* GetLaunchAction(RtcPrivateApi::LaunchAction action) {
+ const char* action_str = kActivateAction;
+ switch (action) {
+ case RtcPrivateApi::LAUNCH_ACTIVATE:
+ action_str = kActivateAction;
+ break;
+ case RtcPrivateApi::LAUNCH_CHAT:
+ action_str = kChatAction;
+ break;
+ case RtcPrivateApi::LAUNCH_VOICE:
+ action_str = kVoiceAction;
+ break;
+ case RtcPrivateApi::LAUNCH_VIDEO:
+ action_str = kVideoAction;
+ break;
+ default:
+ NOTREACHED() << "Unknown action " << action;
+ break;
+ }
+ return action_str;
+}
+
+// Creates JSON payload string for contact web intent data.
+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.
+ base::DictionaryValue dict;
+
+ // TODO(derat): This might require more name extraction magic than this.
+ dict.SetString(kNameIntentField, contact->full_name());
+
+ ListValue* phone_list = new base::ListValue();
+ dict.Set(kPhoneIntentField, phone_list);
+ for (int i = 0; i < contact->phone_numbers_size(); i++) {
+ const Contact_PhoneNumber& phone_number = contact->phone_numbers(i);
+ StringValue* value = Value::CreateStringValue(phone_number.number());
+ if (phone_number.primary())
+ CHECK(phone_list->Insert(0, value));
+ else
+ phone_list->Append(value);
+ }
+
+ ListValue* email_list = new base::ListValue();
+ dict.Set(kPhoneIntentField, email_list);
+ for (int i = 0; i < contact->email_addresses_size(); i++) {
+ const Contact_EmailAddress& email_address = contact->email_addresses(i);
+ StringValue* value = Value::CreateStringValue(email_address.address());
+ if (email_address.primary())
+ CHECK(email_list->Insert(0, value));
+ else
+ email_list->Append(value);
+ }
+
+ std::string data;
+ base::JSONWriter::Write(&dict, &data);
+ return data;
+}
+
+
+} // namespace
+
+
+void RtcPrivateApi::RaiseLaunchEvent(Profile* profile,
+ LaunchAction action,
+ Contact* contact) {
+ if (action == RtcPrivateApi::LAUNCH_ACTIVATE) {
+ extensions::ExtensionSystem::Get(profile)->event_router()->
+ DispatchEventToRenderers(
+ kOnLaunchEvent,
+ scoped_ptr<ListValue>(new ListValue()),
+ profile,
+ GURL());
+ } else {
+ extensions::api::rtc_private::LaunchData launch_data;
+ launch_data.intent.action = GetLaunchAction(action);
+ launch_data.intent.data = GetContactIntentData(contact);
+ launch_data.intent.type = kMimeTypeJson;
+ extensions::ExtensionSystem::Get(profile)->event_router()->
+ DispatchEventToRenderers(
+ kOnLaunchEvent,
+ extensions::api::rtc_private::OnLaunch::Create(launch_data),
+ profile,
+ GURL());
+ }
+}
+
+} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698