OLD | NEW |
---|---|
(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/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 } | |
39 } | |
40 | |
41 ServiceRegistrationManager::~ServiceRegistrationManager() { | |
42 } | |
43 | |
44 ServiceRegistrationManager* ServiceRegistrationManager::GetSharedInstance() { | |
45 return g_lazy_instance.Pointer(); | |
46 } | |
47 | |
48 void ServiceRegistrationManager::AddToRenderFrame( | |
49 content::RenderFrameHost* render_frame_host) { | |
50 content::BrowserContext* context = | |
51 render_frame_host->GetProcess()->GetBrowserContext(); | |
52 content::SiteInstance* site_instance = render_frame_host->GetSiteInstance(); | |
53 GURL site_url = site_instance->GetSiteURL(); | |
54 ExtensionRegistry* registry = ExtensionRegistry::Get(context); | |
55 | |
56 // TODO(sammc): Handle content scripts and web pages that have access to some | |
57 // extension APIs. | |
58 if (!site_url.SchemeIs(kExtensionScheme)) { | |
59 return; | |
60 } | |
61 | |
62 const Extension* extension = | |
63 registry->enabled_extensions().GetByID(site_url.host()); | |
64 DCHECK(extension); | |
65 | |
66 Feature::Context context_type = | |
67 ProcessMap::Get(context)->GetMostLikelyContextType( | |
68 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
| |
69 for (const auto& factory : factories_) { | |
70 // Note: The RenderFrame has not yet navigated to a particular URL so we | |
71 // 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.
| |
72 // for now because we only reach this point for URLs with a scheme of | |
73 // chrome-extension. This will need to change once we begin supporting | |
74 // arbitrary sites URLs that may have access to extensions APIs. | |
75 if (ExtensionAPI::GetSharedInstance() | |
76 ->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
| |
77 .is_available()) { | |
78 factory.second->Register(render_frame_host->GetServiceRegistry()); | |
79 } | |
80 } | |
81 } | |
82 | |
83 } // namespace extensions | |
OLD | NEW |