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

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..cfd0984b1b3b41ed02cf70eeb999dba855ab9626
--- /dev/null
+++ b/chrome/browser/extensions/api/rtc_private/rtc_private_api.cc
@@ -0,0 +1,135 @@
+// 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/command_line.h"
+#include "base/json/json_writer.h"
+#include "base/message_loop.h"
+#include "base/time.h"
+#include "base/stringprintf.h"
Daniel Erat 2012/09/05 19:28:32 nit: alphabetize
zel 2012/09/05 19:56:03 Done.
+#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/chrome_switches.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";
+// 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";
+
+const char kIntentField[] = "intent";
+const char kActionField[] = "action";
+const char kDataField[] = "data";
+const char kTypeField[] = "type";
+
+// 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;
Daniel Erat 2012/09/05 19:28:32 nit: add a default case with NOTREACHED() << "Unkn
zel 2012/09/05 19:56:03 Done.
+ }
+ return action_str;
+}
+
+// Creates JSON payload string for contact web intent data.
+std::string GetContactIntentData(Contact* contact) {
+ scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
Daniel Erat 2012/09/05 19:28:32 nit: any reason that you actually need a scoped_pt
zel 2012/09/05 19:56:03 Done.
+
+ // TODO(derat): This might require more name extraction magic than this.
+ dict->SetString(kNameIntentField, contact->full_name());
+
+ int i;
+ ListValue* phone_list = new base::ListValue();
+ dict->Set(kPhoneIntentField, phone_list);
+ for (i = 0; i < contact->phone_numbers_size(); i++) {
Daniel Erat 2012/09/05 19:28:32 nit: move 'i' declaration into the loop condition
zel 2012/09/05 19:56:03 Done.
+ const Contact_PhoneNumber& phone_number = contact->phone_numbers(i);
+ phone_list->Append(Value::CreateStringValue(phone_number.number()));
+ }
+
+ ListValue* email_list = new base::ListValue();
+ dict->Set(kPhoneIntentField, email_list);
+ for (i = 0; i < contact->email_addresses_size(); i++) {
Daniel Erat 2012/09/05 19:28:32 we talked earlier about sorting phone numbers and
zel 2012/09/05 19:56:03 Done.
+ const Contact_EmailAddress& email_address = contact->email_addresses(i);
+ email_list->Append(Value::CreateStringValue(email_address.address()));
+ }
+
+ std::string data;
+ base::JSONWriter::Write(dict.get(), &data);
+ return data;
+}
+
+
+} // namespace
+
+
+void RtcPrivateApi::RaiseLaunchEvent(Profile* profile,
+ LaunchAction action,
+ Contact* contact) {
+ CommandLine* command_line = CommandLine::ForCurrentProcess();
+ if (!command_line->HasSwitch(switches::kEnableContacts))
Daniel Erat 2012/09/05 19:28:32 is this something that you actually need to check
zel 2012/09/05 19:56:03 Fair enough. Removed.
+ return;
+
+ scoped_ptr<ListValue> args(new ListValue());
+ if (action != RtcPrivateApi::LAUNCH_ACTIVATE) {
+ DictionaryValue* launch_data = new DictionaryValue();
+ args->Append(launch_data);
+ DictionaryValue* intent = new DictionaryValue();
+ launch_data->Set(kIntentField, intent);
+ intent->SetString(kActionField, GetLaunchAction(action));
+ intent->SetString(kDataField, GetContactIntentData(contact));
+ intent->SetString(kTypeField, kMimeTypeJson);
+ }
+
+ extensions::ExtensionSystem::Get(profile)->event_router()->
+ DispatchEventToRenderers(
+ kOnLaunchEvent,
+ args.Pass(),
+ profile,
+ GURL());
+}
+
+} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698