Chromium Code Reviews| 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..6ae775a53b6b68d9666788f8fcf60c886a4e50a0 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 { |
| @@ -22,7 +23,14 @@ const char kCastServiceType[] = "_googlecast._tcp.local"; |
| const char kPrivetServiceType[] = "_privet._tcp.local"; |
| const char kTestServiceType[] = "_testing._tcp.local"; |
| -bool IsServiceTypeWhitelisted(const std::string& service_type) { |
| +bool IsServiceTypeWhitelisted(const std::string& service_type, |
| + bool is_extension) { |
| + // The mdns API is available to apps without restrictions. A whitelisted set |
| + // of extensions is allowed to use the mdns API, but only to connect to a |
| + // whitelisted set of service types. |
|
not at google - send to devlin
2014/12/10 18:23:04
Note that a more correct check here would be is_pl
Red Daly
2015/01/26 21:55:33
Done, but in UpdateMDnsListeners.
|
| + if (!is_extension) { |
|
not at google - send to devlin
2014/12/10 18:23:05
I actually think that doing all of this work insid
Red Daly
2015/01/26 21:55:33
I took the second approach (kept function static a
|
| + return true; |
| + } |
| return service_type == kCastServiceType || |
| service_type == kPrivetServiceType || |
| service_type == kTestServiceType; |
| @@ -109,21 +117,27 @@ void MDnsAPI::UpdateMDnsListeners(const EventListenerInfo& details) { |
| std::set<std::string> removed_service_types = |
| base::STLSetDifference<std::set<std::string> >( |
| service_types_, new_service_types); |
| + service_types_ = new_service_types; |
|
mark a. foltz
2014/12/09 23:56:34
If we update |service_types_| here for a disabled
not at google - send to devlin
2014/12/10 18:23:05
This shouldn't happen because disabled extensions
|
| // Update the registry. |
| DnsSdRegistry* registry = dns_sd_registry(); |
|
mark a. foltz
2014/12/09 23:56:34
This doesn't need to be done until after |extensio
Red Daly
2015/01/26 21:55:33
The control flow changed a little. At this point,
|
| + |
| + const Extension* extension = ExtensionRegistry::Get(browser_context_)-> |
| + GetExtensionById(details.extension_id, ExtensionRegistry::ENABLED); |
|
mark a. foltz
2014/12/09 23:56:34
Are only ENABLED extensions allowed to register ev
not at google - send to devlin
2014/12/10 18:23:04
Yes I think that EVERYTHING was correct, whoops, b
Red Daly
2015/01/26 21:55:33
I checked and this is called when an extension is
|
| + if (!extension) { |
| + return; |
| + } |
| + |
|
mark a. foltz
2014/12/09 23:56:34
Slight preference for declaring a bool here and le
Red Daly
2015/01/26 21:55:33
Obsolete (moved IsServiceTypeWhitelisted call to l
|
| for (std::set<std::string>::iterator it = added_service_types.begin(); |
| it != added_service_types.end(); ++it) { |
| - if (IsServiceTypeWhitelisted(*it)) |
| + if (IsServiceTypeWhitelisted(*it, extension->is_extension())) |
| registry->RegisterDnsSdListener(*it); |
| } |
| for (std::set<std::string>::iterator it = removed_service_types.begin(); |
| it != removed_service_types.end(); ++it) { |
| - if (IsServiceTypeWhitelisted(*it)) |
| + if (IsServiceTypeWhitelisted(*it, extension->is_extension())) |
| registry->UnregisterDnsSdListener(*it); |
| } |
| - |
| - service_types_ = new_service_types; |
| } |
| void MDnsAPI::OnDnsSdEvent(const std::string& service_type, |