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 2a7c41d210931d1540e61b8cb89fe402a203e1e8..5cd0b9a38b67263a53579da38e4cbcddffb5fe95 100644 |
| --- a/chrome/browser/extensions/api/mdns/mdns_api.cc |
| +++ b/chrome/browser/extensions/api/mdns/mdns_api.cc |
| @@ -9,7 +9,11 @@ |
| #include "base/lazy_instance.h" |
| #include "chrome/browser/extensions/extension_service.h" |
| #include "chrome/common/extensions/api/mdns.h" |
| +#include "content/public/browser/render_process_host.h" |
| +#include "content/public/browser/render_view_host.h" |
| +#include "extensions/browser/extension_host.h" |
| #include "extensions/browser/extension_registry.h" |
| +#include "extensions/common/extension_messages.h" |
| namespace extensions { |
| @@ -140,6 +144,17 @@ void MDnsAPI::OnDnsSdEvent(const std::string& service_type, |
| std::vector<linked_ptr<mdns::MDnsService> > args; |
| for (DnsSdRegistry::DnsSdServiceList::const_iterator it = services.begin(); |
| it != services.end(); ++it) { |
| + if (static_cast<long>(args.size()) == |
| + api::mdns::maxServiceInstancesPerEvent) { |
| + std::ostringstream s; |
| + s << "Truncating service instances in onServiceList event to max: " |
| + << api::mdns::maxServiceInstancesPerEvent; |
|
not at google - send to devlin
2015/04/02 22:36:22
I think it's more common to use StringPrintf rathe
Red Daly
2015/04/03 17:58:56
Done.
|
| + WriteToConsole(service_type, |
| + content::CONSOLE_MESSAGE_LEVEL_WARNING, |
| + s.str()); |
| + VLOG(logging::LOG_WARNING) << s.str(); |
| + break; |
| + } |
| linked_ptr<mdns::MDnsService> mdns_service = |
| make_linked_ptr(new mdns::MDnsService); |
| mdns_service->service_name = (*it).service_name; |
| @@ -162,4 +177,53 @@ void MDnsAPI::OnDnsSdEvent(const std::string& service_type, |
| extensions::EventRouter::Get(browser_context_)->BroadcastEvent(event.Pass()); |
| } |
| +void MDnsAPI::WriteToConsole(const std::string& service_type, |
|
not at google - send to devlin
2015/04/02 22:36:22
I'm a bit lost sorry - why is so much code needed
Red Daly
2015/04/03 17:58:55
There is one JS console per extension. This code
not at google - send to devlin
2015/04/03 18:16:58
Ohh I see. So these service registation restrictio
|
| + content::ConsoleMessageLevel level, |
| + const std::string& message) { |
| + std::set<std::string> extension_ids; |
| + |
| + // Check all listeners for service type filters. |
| + for (const auto& listener : |
| + extensions::EventRouter::Get(browser_context_)->listeners() |
| + .GetEventListenersByName(mdns::OnServiceList::kEventName)) { |
| + base::DictionaryValue* filter = (listener->filter()); |
| + |
| + std::string filter_value; |
| + filter->GetStringASCII(kEventFilterServiceTypeKey, &filter_value); |
| + if (filter_value.empty()) |
| + continue; |
| + |
| + const Extension* extension = ExtensionRegistry::Get(browser_context_)-> |
| + enabled_extensions().GetByID(listener->extension_id()); |
| + // 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; |
| + |
| + extension_ids.insert(listener->extension_id()); |
| + } |
| + |
| + // Log to the consoles of the background pages of relevant listeners. |
| + for (const std::string& extension_id : extension_ids) { |
| + extensions::ExtensionHost* host = |
| + extensions::ProcessManager::Get(browser_context_) |
| + ->GetBackgroundHostForExtension(extension_id); |
| + if (!host) |
| + continue; |
| + content::RenderProcessHost* rph = host->render_process_host(); |
| + content::RenderViewHost* rvh = host->render_view_host(); |
| + if (!rvh || !rph) |
| + continue; |
| + rph->Send(new ExtensionMsg_AddMessageToConsole( |
| + rvh->GetRoutingID(), |
| + level, |
| + message)); |
| + } |
| +} |
| + |
| } // namespace extensions |