| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "extensions/browser/service_registration_manager.h" | 5 #include "extensions/browser/service_registration_manager.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
| 9 #include "content/public/browser/browser_thread.h" | 9 #include "content/public/browser/browser_thread.h" |
| 10 #include "content/public/browser/render_frame_host.h" | 10 #include "content/public/browser/render_frame_host.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 } | 38 } |
| 39 } | 39 } |
| 40 | 40 |
| 41 ServiceRegistrationManager::~ServiceRegistrationManager() { | 41 ServiceRegistrationManager::~ServiceRegistrationManager() { |
| 42 } | 42 } |
| 43 | 43 |
| 44 ServiceRegistrationManager* ServiceRegistrationManager::GetSharedInstance() { | 44 ServiceRegistrationManager* ServiceRegistrationManager::GetSharedInstance() { |
| 45 return g_lazy_instance.Pointer(); | 45 return g_lazy_instance.Pointer(); |
| 46 } | 46 } |
| 47 | 47 |
| 48 void ServiceRegistrationManager::ClearOverridesForTest() { |
| 49 test_factories_.clear(); |
| 50 } |
| 51 |
| 48 void ServiceRegistrationManager::AddToRenderFrame( | 52 void ServiceRegistrationManager::AddToRenderFrame( |
| 49 content::RenderFrameHost* render_frame_host) { | 53 content::RenderFrameHost* render_frame_host) { |
| 50 content::BrowserContext* context = | 54 content::BrowserContext* context = |
| 51 render_frame_host->GetProcess()->GetBrowserContext(); | 55 render_frame_host->GetProcess()->GetBrowserContext(); |
| 52 content::SiteInstance* site_instance = render_frame_host->GetSiteInstance(); | 56 content::SiteInstance* site_instance = render_frame_host->GetSiteInstance(); |
| 53 GURL site_url = site_instance->GetSiteURL(); | 57 GURL site_url = site_instance->GetSiteURL(); |
| 54 ExtensionRegistry* registry = ExtensionRegistry::Get(context); | 58 ExtensionRegistry* registry = ExtensionRegistry::Get(context); |
| 55 | 59 |
| 56 // TODO(sammc): Handle content scripts and web pages that have access to some | 60 // TODO(sammc): Handle content scripts and web pages that have access to some |
| 57 // extension APIs. | 61 // extension APIs. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 68 extension, render_frame_host->GetProcess()->GetID()); | 72 extension, render_frame_host->GetProcess()->GetID()); |
| 69 for (const auto& factory : factories_) { | 73 for (const auto& factory : factories_) { |
| 70 // Note: The RenderFrame has not yet navigated to a particular URL so we | 74 // 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 | 75 // pass |site_url| as the URL for permission checking. This is sufficient |
| 72 // for now because we only reach this point for URLs with a scheme of | 76 // 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 | 77 // chrome-extension. This will need to change once we begin supporting |
| 74 // arbitrary sites URLs that may have access to extensions APIs. | 78 // arbitrary sites URLs that may have access to extensions APIs. |
| 75 if (ExtensionAPI::GetSharedInstance() | 79 if (ExtensionAPI::GetSharedInstance() |
| 76 ->IsAvailable(factory.first, extension, context_type, site_url) | 80 ->IsAvailable(factory.first, extension, context_type, site_url) |
| 77 .is_available()) { | 81 .is_available()) { |
| 78 factory.second->Register(render_frame_host->GetServiceRegistry()); | 82 auto test_factory = test_factories_.find(factory.second->GetName()); |
| 83 if (test_factory != test_factories_.end()) { |
| 84 test_factory->second->Register(render_frame_host->GetServiceRegistry()); |
| 85 } else { |
| 86 factory.second->Register(render_frame_host->GetServiceRegistry()); |
| 87 } |
| 79 } | 88 } |
| 80 } | 89 } |
| 81 } | 90 } |
| 82 | 91 |
| 83 } // namespace extensions | 92 } // namespace extensions |
| OLD | NEW |