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

Unified Diff: extensions/browser/service_registration_manager.cc

Issue 652793002: Add service registration for apps APIs implemented as mojo services. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 6 years, 2 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: extensions/browser/service_registration_manager.cc
diff --git a/extensions/browser/service_registration_manager.cc b/extensions/browser/service_registration_manager.cc
new file mode 100644
index 0000000000000000000000000000000000000000..1a727bf73a3b943b241fbe423261d267ce0905b2
--- /dev/null
+++ b/extensions/browser/service_registration_manager.cc
@@ -0,0 +1,83 @@
+// Copyright 2014 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 "extensions/browser/service_registration_manager.h"
+
+#include "base/command_line.h"
+#include "base/lazy_instance.h"
+#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/render_frame_host.h"
+#include "content/public/browser/render_process_host.h"
+#include "content/public/browser/site_instance.h"
+#include "device/serial/serial_service_impl.h"
+#include "extensions/browser/extension_registry.h"
+#include "extensions/browser/process_map.h"
+#include "extensions/common/constants.h"
+#include "extensions/common/extension_api.h"
+#include "extensions/common/switches.h"
+
+namespace extensions {
+namespace {
+
+base::LazyInstance<ServiceRegistrationManager> g_lazy_instance =
+ LAZY_INSTANCE_INITIALIZER;
+
+} // namespace
+
+ServiceRegistrationManager::ServiceRegistrationManager() {
+ if (base::CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kEnableMojoSerialService)) {
+ AddServiceFactory(
+ "serial",
+ base::Bind(device::SerialServiceImpl::CreateOnMessageLoop,
+ content::BrowserThread::GetMessageLoopProxyForThread(
+ content::BrowserThread::FILE),
+ content::BrowserThread::GetMessageLoopProxyForThread(
+ content::BrowserThread::IO)));
+ }
+}
+
+ServiceRegistrationManager::~ServiceRegistrationManager() {
+}
+
+ServiceRegistrationManager* ServiceRegistrationManager::GetSharedInstance() {
+ return g_lazy_instance.Pointer();
+}
+
+void ServiceRegistrationManager::AddToRenderFrame(
+ content::RenderFrameHost* render_frame_host) {
+ content::BrowserContext* context =
+ render_frame_host->GetProcess()->GetBrowserContext();
+ content::SiteInstance* site_instance = render_frame_host->GetSiteInstance();
+ GURL site_url = site_instance->GetSiteURL();
+ ExtensionRegistry* registry = ExtensionRegistry::Get(context);
+
+ // TODO(sammc): Handle content scripts and web pages that have access to some
+ // extension APIs.
+ if (!site_url.SchemeIs(kExtensionScheme)) {
+ return;
+ }
+
+ const Extension* extension =
+ registry->enabled_extensions().GetByID(site_url.host());
+ DCHECK(extension);
+
+ Feature::Context context_type =
+ ProcessMap::Get(context)->GetMostLikelyContextType(
+ extension, render_frame_host->GetProcess()->GetID());
raymes 2014/10/15 20:22:49 I don't really understand the details of this. Is
Sam McNally 2014/10/20 00:22:07 I don't think this will make anything worse than i
raymes 2014/10/20 02:12:55 Thanks. kalman@ it would be great if you could rev
not at google - send to devlin 2014/10/20 18:28:31 Short answer: yes. Long answer: it's complicated
+ for (const auto& factory : factories_) {
+ // Note: The RenderFrame has not yet navigated to a particular URL so we
+ // pass |site_url| as the URL for permission checking. This is sufficient
raymes 2014/10/15 20:22:50 What other URL would we pass? I'm not quite sure I
Sam McNally 2014/10/20 00:22:07 The actual URL loaded by the frame. This might mat
raymes 2014/10/20 02:12:55 Maybe we can name "site_url"->"extension_url" for
Sam McNally 2014/10/20 07:28:19 Done.
+ // for now because we only reach this point for URLs with a scheme of
+ // chrome-extension. This will need to change once we begin supporting
+ // arbitrary sites URLs that may have access to extensions APIs.
+ if (ExtensionAPI::GetSharedInstance()
+ ->IsAvailable(factory.first, extension, context_type, site_url)
raymes 2014/10/15 20:22:50 Is it possible for the security context to of a Re
Sam McNally 2014/10/20 00:22:07 As far as I can tell from the documentation the an
+ .is_available()) {
+ factory.second->Register(render_frame_host->GetServiceRegistry());
+ }
+ }
+}
+
+} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698