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

Unified Diff: chrome/browser/extensions/api/mdns/mdns_api.cc

Issue 668983003: Enable chrome.mdns for Chrome Apps (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix unsubscription bug and refactor according to comments Created 5 years, 11 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
« no previous file with comments | « no previous file | chrome/common/extensions/api/_permission_features.json » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/extensions/api/mdns/mdns_api.cc
diff --git a/chrome/browser/extensions/api/mdns/mdns_api.cc b/chrome/browser/extensions/api/mdns/mdns_api.cc
index 572ae1eec7b08e50906f96f94aeda0314b75d1c0..0a8f3337bd37a52912c03f195603abc26087604b 100644
--- a/chrome/browser/extensions/api/mdns/mdns_api.cc
+++ b/chrome/browser/extensions/api/mdns/mdns_api.cc
@@ -10,6 +10,7 @@
#include "base/profiler/scoped_profile.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/common/extensions/api/mdns.h"
+#include "extensions/browser/extension_registry.h"
namespace extensions {
@@ -86,7 +87,7 @@ void MDnsAPI::OnListenerRemoved(const EventListenerInfo& details) {
void MDnsAPI::UpdateMDnsListeners(const EventListenerInfo& details) {
std::set<std::string> new_service_types;
- // Check all listeners for service type filers.
+ // Check all listeners for service type filters.
const EventListenerMap::ListenerList& listeners =
extensions::EventRouter::Get(browser_context_)
->listeners()
@@ -99,6 +100,19 @@ void MDnsAPI::UpdateMDnsListeners(const EventListenerInfo& details) {
filter->GetStringASCII(kEventFilterServiceTypeKey, &filter_value);
if (filter_value.empty())
continue;
+
+ const Extension* extension = ExtensionRegistry::Get(browser_context_)->
+ GetExtensionById((*it)->extension_id(), ExtensionRegistry::ENABLED);
not at google - send to devlin 2015/01/26 22:13:35 Just do: ... = ExtensionRegistry::Get(...)->enabl
Red Daly 2015/01/26 23:46:23 Done.
+ // Don't listen for services associated only with disabled extensions.
+ if (!extension)
+ continue;
+
+ // Platform apps may query for all services; other types of extensions are
+ // restricted to a whitelist.
+ if (!extension->is_platform_app() &&
+ !IsServiceTypeWhitelisted(filter_value))
+ continue;
+
new_service_types.insert(filter_value);
}
@@ -112,17 +126,16 @@ void MDnsAPI::UpdateMDnsListeners(const EventListenerInfo& details) {
// Update the registry.
DnsSdRegistry* registry = dns_sd_registry();
+
for (std::set<std::string>::iterator it = added_service_types.begin();
it != added_service_types.end(); ++it) {
- if (IsServiceTypeWhitelisted(*it))
- registry->RegisterDnsSdListener(*it);
+ registry->RegisterDnsSdListener(*it);
+
not at google - send to devlin 2015/01/26 22:13:35 Nits: delete this empty line, don't add an extra o
Red Daly 2015/01/26 23:46:23 Done.
}
for (std::set<std::string>::iterator it = removed_service_types.begin();
it != removed_service_types.end(); ++it) {
- if (IsServiceTypeWhitelisted(*it))
- registry->UnregisterDnsSdListener(*it);
+ registry->UnregisterDnsSdListener(*it);
}
-
service_types_ = new_service_types;
}
@@ -148,8 +161,6 @@ void MDnsAPI::OnDnsSdEvent(const std::string& service_type,
event->restrict_to_browser_context = browser_context_;
event->filter_info.SetServiceType(service_type);
- VLOG(1) << "Broadcasting OnServiceList event: " << event.get();
-
// TODO(justinlin): To avoid having listeners without filters getting all
// events, modify API to have this event require filters.
extensions::EventRouter::Get(browser_context_)->BroadcastEvent(event.Pass());
« no previous file with comments | « no previous file | chrome/common/extensions/api/_permission_features.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698