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

Side by Side Diff: extensions/browser/mojo/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, 1 month 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 unified diff | Download patch
« no previous file with comments | « extensions/browser/mojo/service_registration_manager.h ('k') | extensions/common/switches.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "extensions/browser/mojo/service_registration_manager.h"
6
7 #include "base/command_line.h"
8 #include "base/lazy_instance.h"
9 #include "content/public/browser/browser_thread.h"
10 #include "content/public/browser/render_frame_host.h"
11 #include "content/public/browser/render_process_host.h"
12 #include "content/public/browser/site_instance.h"
13 #include "device/serial/serial_service_impl.h"
14 #include "extensions/browser/extension_registry.h"
15 #include "extensions/browser/process_map.h"
16 #include "extensions/common/constants.h"
17 #include "extensions/common/extension_api.h"
18 #include "extensions/common/switches.h"
19
20 namespace extensions {
21 namespace {
22
23 base::LazyInstance<ServiceRegistrationManager> g_lazy_instance =
24 LAZY_INSTANCE_INITIALIZER;
25
26 } // namespace
27
28 ServiceRegistrationManager::ServiceRegistrationManager() {
29 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
30 switches::kEnableMojoSerialService)) {
31 AddServiceFactory(
32 "serial",
33 base::Bind(device::SerialServiceImpl::CreateOnMessageLoop,
34 content::BrowserThread::GetMessageLoopProxyForThread(
35 content::BrowserThread::FILE),
36 content::BrowserThread::GetMessageLoopProxyForThread(
37 content::BrowserThread::IO),
38 content::BrowserThread::GetMessageLoopProxyForThread(
39 content::BrowserThread::UI)));
40 }
41 }
42
43 ServiceRegistrationManager::~ServiceRegistrationManager() {
44 }
45
46 ServiceRegistrationManager* ServiceRegistrationManager::GetSharedInstance() {
47 return g_lazy_instance.Pointer();
48 }
49
50 void ServiceRegistrationManager::AddServicesToRenderFrame(
51 content::RenderFrameHost* render_frame_host) {
52 content::BrowserContext* context =
53 render_frame_host->GetProcess()->GetBrowserContext();
54 content::SiteInstance* site_instance = render_frame_host->GetSiteInstance();
55 GURL extension_url = site_instance->GetSiteURL();
56 ExtensionRegistry* registry = ExtensionRegistry::Get(context);
57
58 // TODO(sammc): Handle content scripts and web pages that have access to some
59 // extension APIs.
60 if (!extension_url.SchemeIs(kExtensionScheme)) {
61 return;
62 }
63
64 const Extension* extension =
65 registry->enabled_extensions().GetByID(extension_url.host());
66 if (!extension)
67 return;
68
69 Feature::Context context_type =
70 ProcessMap::Get(context)->GetMostLikelyContextType(
71 extension, render_frame_host->GetProcess()->GetID());
72 for (const auto& factory : factories_) {
73 auto availability = ExtensionAPI::GetSharedInstance()->IsAvailable(
74 factory.first, extension, context_type, extension_url);
75 if (availability.is_available())
76 factory.second->Register(render_frame_host->GetServiceRegistry());
77 }
78 }
79
80 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/mojo/service_registration_manager.h ('k') | extensions/common/switches.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698