// Copyright 2015 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/chrome_mojo_service_registration.h"

#include "base/bind.h"
#include "base/command_line.h"
#include "base/logging.h"
#include "chrome/common/chrome_switches.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/common/service_registry.h"
#include "extensions/common/extension.h"
#include "extensions/common/permissions/api_permission.h"
#include "extensions/common/permissions/permissions_data.h"
#include "extensions/common/switches.h"

#if defined(ENABLE_MEDIA_ROUTER)
#include "chrome/browser/media/router/media_router_mojo_impl.h"
#endif

namespace extensions {

void RegisterChromeServicesForFrame(content::RenderFrameHost* render_frame_host,
                                    const Extension* extension) {
  DCHECK(render_frame_host);
  DCHECK(extension);

  content::ServiceRegistry* service_registry =
      render_frame_host->GetServiceRegistry();

#if defined(ENABLE_MEDIA_ROUTER)
  if (base::CommandLine::ForCurrentProcess()->HasSwitch(
          ::switches::kEnableMediaRouter)) {
    if (extension->permissions_data()->HasAPIPermission(
            APIPermission::kMediaRouterPrivate)) {
      service_registry->AddService(base::Bind(
          media_router::MediaRouterMojoImpl::BindToRequest, extension->id(),
          render_frame_host->GetProcess()->GetBrowserContext()));
    }
  }
#endif  // defined(ENABLE_MEDIA_ROUTER)
}

}  // namespace extensions

// Copyright 2015 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/chrome_mojo_service_registration.h"

#include "base/logging.h"

namespace extensions {

void RegisterChromeServicesForFrame(content::RenderFrameHost* render_frame_host,
                                    const Extension* extension) {
  DCHECK(render_frame_host);
  DCHECK(extension);

  // TODO(kmarshall): Add Mojo service registration.
}

}  // namespace extensions

--- 
+++ 
@@ -4,7 +4,21 @@
 
 #include "chrome/browser/extensions/chrome_mojo_service_registration.h"
 
+#include "base/bind.h"
+#include "base/command_line.h"
 #include "base/logging.h"
+#include "chrome/common/chrome_switches.h"
+#include "content/public/browser/render_frame_host.h"
+#include "content/public/browser/render_process_host.h"
+#include "content/public/common/service_registry.h"
+#include "extensions/common/extension.h"
+#include "extensions/common/permissions/api_permission.h"
+#include "extensions/common/permissions/permissions_data.h"
+#include "extensions/common/switches.h"
+
+#if defined(ENABLE_MEDIA_ROUTER)
+#include "chrome/browser/media/router/media_router_mojo_impl.h"
+#endif
 
 namespace extensions {
 
@@ -13,7 +27,20 @@
   DCHECK(render_frame_host);
   DCHECK(extension);
 
-  // TODO(kmarshall): Add Mojo service registration.
+  content::ServiceRegistry* service_registry =
+      render_frame_host->GetServiceRegistry();
+
+#if defined(ENABLE_MEDIA_ROUTER)
+  if (base::CommandLine::ForCurrentProcess()->HasSwitch(
+          ::switches::kEnableMediaRouter)) {
+    if (extension->permissions_data()->HasAPIPermission(
+            APIPermission::kMediaRouterPrivate)) {
+      service_registry->AddService(base::Bind(
+          media_router::MediaRouterMojoImpl::BindToRequest, extension->id(),
+          render_frame_host->GetProcess()->GetBrowserContext()));
+    }
+  }
+#endif  // defined(ENABLE_MEDIA_ROUTER)
 }
 
 }  // namespace extensions
Add Media Router Mojo service to the renderer service registry.
Guard access to the Media Router service using a manifest permission.

BUG=464205
R=imcheng

Review URL: https://codereview.chromium.org/1164713003

Cr-Commit-Position: 972c6d2dc6dd5efdad1377c0d224e03eb8f276f7@{#332395}
