Chromium Code Reviews| Index: extensions/renderer/dispatcher.cc |
| diff --git a/extensions/renderer/dispatcher.cc b/extensions/renderer/dispatcher.cc |
| index e870f86b52338d30e4b2f81f49011ba8edf59c44..8e0ad7fb4a5611359554a9d15a03bb4e6ff6fbf4 100644 |
| --- a/extensions/renderer/dispatcher.cc |
| +++ b/extensions/renderer/dispatcher.cc |
| @@ -119,6 +119,8 @@ static const int64 kMaxExtensionIdleHandlerDelayMs = 5 * 60 * 1000; |
| static const char kEventDispatchFunction[] = "dispatchEvent"; |
| static const char kOnSuspendEvent[] = "runtime.onSuspend"; |
| static const char kOnSuspendCanceledEvent[] = "runtime.onSuspendCanceled"; |
| +static base::LazyInstance<ExtensionSet> g_extensions = |
| + LAZY_INSTANCE_INITIALIZER; |
|
not at google - send to devlin
2015/08/13 23:33:55
If we're doing this, ExtensionSet should handle it
not at google - send to devlin
2015/08/13 23:34:31
I mean g_instance variable.
|
| // Returns the global value for "chrome" from |context|. If one doesn't exist |
| // creates a new object for it. |
| @@ -202,10 +204,10 @@ Dispatcher::Dispatcher(DispatcherDelegate* delegate) |
| } |
| script_context_set_.reset( |
| - new ScriptContextSet(&extensions_, &active_extension_ids_)); |
| - user_script_set_manager_.reset(new UserScriptSetManager(&extensions_)); |
| - script_injection_manager_.reset( |
| - new ScriptInjectionManager(&extensions_, user_script_set_manager_.get())); |
| + new ScriptContextSet(&g_extensions.Get(), &active_extension_ids_)); |
| + user_script_set_manager_.reset(new UserScriptSetManager(&g_extensions.Get())); |
| + script_injection_manager_.reset(new ScriptInjectionManager( |
| + &g_extensions.Get(), user_script_set_manager_.get())); |
| user_script_set_manager_observer_.Add(user_script_set_manager_.get()); |
| request_sender_.reset(new RequestSender(this)); |
| PopulateSourceMap(); |
| @@ -214,6 +216,10 @@ Dispatcher::Dispatcher(DispatcherDelegate* delegate) |
| Dispatcher::~Dispatcher() { |
| } |
| +const ExtensionSet* Dispatcher::extensions() const { |
| + return &g_extensions.Get(); |
| +} |
| + |
| void Dispatcher::OnRenderFrameCreated(content::RenderFrame* render_frame) { |
| script_injection_manager_->OnRenderFrameCreated(render_frame); |
| } |
| @@ -222,7 +228,7 @@ bool Dispatcher::IsExtensionActive(const std::string& extension_id) const { |
| bool is_active = |
| active_extension_ids_.find(extension_id) != active_extension_ids_.end(); |
| if (is_active) |
| - CHECK(extensions_.Contains(extension_id)); |
| + CHECK(g_extensions.Get().Contains(extension_id)); |
| return is_active; |
| } |
| @@ -330,7 +336,7 @@ void Dispatcher::DidCreateDocumentElement(blink::WebLocalFrame* frame) { |
| frame, frame->document().url(), true /* match_about_blank */); |
| const Extension* extension = |
| - extensions_.GetExtensionOrAppByURL(effective_document_url); |
| + g_extensions.Get().GetExtensionOrAppByURL(effective_document_url); |
| if (extension && |
| (extension->is_extension() || extension->is_platform_app())) { |
| @@ -412,7 +418,7 @@ void Dispatcher::InvokeModuleSystemMethod(content::RenderFrame* render_frame, |
| // Tell the browser process when an event has been dispatched with a lazy |
| // background page active. |
| - const Extension* extension = extensions_.GetByID(extension_id); |
| + const Extension* extension = g_extensions.Get().GetByID(extension_id); |
| if (extension && BackgroundInfo::HasLazyBackgroundPage(extension) && |
| module_name == kEventBindings && |
| function_name == kEventDispatchFunction) { |
| @@ -701,7 +707,7 @@ void Dispatcher::RegisterNativeHandlers(ModuleSystem* module_system, |
| } |
| void Dispatcher::LoadExtensionForTest(const Extension* extension) { |
| - CHECK(extensions_.Insert(extension)); |
| + CHECK(g_extensions.Get().Insert(extension)); |
| } |
| bool Dispatcher::OnControlMessageReceived(const IPC::Message& message) { |
| @@ -755,7 +761,7 @@ void Dispatcher::WebKitInitialized() { |
| // Initialize host permissions for any extensions that were activated before |
| // WebKit was initialized. |
| for (const std::string& extension_id : active_extension_ids_) { |
| - const Extension* extension = extensions_.GetByID(extension_id); |
| + const Extension* extension = g_extensions.Get().GetByID(extension_id); |
| CHECK(extension); |
| InitOriginPermissions(extension); |
| } |
| @@ -789,7 +795,7 @@ void Dispatcher::OnRenderProcessShutdown() { |
| } |
| void Dispatcher::OnActivateExtension(const std::string& extension_id) { |
| - const Extension* extension = extensions_.GetByID(extension_id); |
| + const Extension* extension = g_extensions.Get().GetByID(extension_id); |
| if (!extension) { |
| // Extension was activated but was never loaded. This probably means that |
| // the renderer failed to load it (or the browser failed to tell us when it |
| @@ -888,8 +894,8 @@ void Dispatcher::OnLoaded( |
| // Dispatcher is attached to a RenderThread. Presumably there is a |
| // mismatch there. In theory one would think it's possible for the |
| // browser to figure this out itself - but again, cost/benefit. |
| - if (!extensions_.Contains(extension->id())) |
| - extensions_.Insert(extension); |
| + if (!g_extensions.Get().Contains(extension->id())) |
| + g_extensions.Get().Insert(extension); |
| } |
| // Update the available bindings for all contexts. These may have changed if |
| @@ -952,7 +958,7 @@ void Dispatcher::OnTransferBlobs(const std::vector<std::string>& blob_uuids) { |
| void Dispatcher::OnUnloaded(const std::string& id) { |
| // See comment in OnLoaded for why it would be nice, but perhaps incorrect, |
| // to CHECK here rather than guarding. |
| - if (!extensions_.Remove(id)) |
| + if (!g_extensions.Get().Remove(id)) |
| return; |
| active_extension_ids_.erase(id); |
| @@ -988,7 +994,7 @@ void Dispatcher::OnUnloaded(const std::string& id) { |
| void Dispatcher::OnUpdatePermissions( |
| const ExtensionMsg_UpdatePermissions_Params& params) { |
| - const Extension* extension = extensions_.GetByID(params.extension_id); |
| + const Extension* extension = g_extensions.Get().GetByID(params.extension_id); |
| if (!extension) |
| return; |
| @@ -1013,7 +1019,7 @@ void Dispatcher::OnUpdateTabSpecificPermissions(const GURL& visible_url, |
| const URLPatternSet& new_hosts, |
| bool update_origin_whitelist, |
| int tab_id) { |
| - const Extension* extension = extensions_.GetByID(extension_id); |
| + const Extension* extension = g_extensions.Get().GetByID(extension_id); |
| if (!extension) |
| return; |
| @@ -1039,7 +1045,7 @@ void Dispatcher::OnClearTabSpecificPermissions( |
| bool update_origin_whitelist, |
| int tab_id) { |
| for (const std::string& id : extension_ids) { |
| - const Extension* extension = extensions_.GetByID(id); |
| + const Extension* extension = g_extensions.Get().GetByID(id); |
| if (extension) { |
| URLPatternSet old_effective = |
| extension->permissions_data()->GetEffectiveHostPermissions(); |
| @@ -1280,7 +1286,7 @@ bool Dispatcher::IsRuntimeAvailableToContext(ScriptContext* context) { |
| context->GetAvailability("surfaceWorkerInternal").is_available()) { |
| return true; |
| } |
| - for (const auto& extension : extensions_) { |
| + for (const auto& extension : g_extensions.Get()) { |
| ExternallyConnectableInfo* info = static_cast<ExternallyConnectableInfo*>( |
| extension->GetManifestData(manifest_keys::kExternallyConnectable)); |
| if (info && info->matches.MatchesURL(context->GetURL())) |
| @@ -1291,7 +1297,7 @@ bool Dispatcher::IsRuntimeAvailableToContext(ScriptContext* context) { |
| void Dispatcher::UpdateContentCapabilities(ScriptContext* context) { |
| APIPermissionSet permissions; |
| - for (const auto& extension : extensions_) { |
| + for (const auto& extension : g_extensions.Get()) { |
| const ContentCapabilitiesInfo& info = |
| ContentCapabilitiesInfo::Get(extension.get()); |
| if (info.url_patterns.MatchesURL(context->GetURL())) { |
| @@ -1318,7 +1324,7 @@ bool Dispatcher::IsWithinPlatformApp() { |
| for (std::set<std::string>::iterator iter = active_extension_ids_.begin(); |
| iter != active_extension_ids_.end(); |
| ++iter) { |
| - const Extension* extension = extensions_.GetByID(*iter); |
| + const Extension* extension = g_extensions.Get().GetByID(*iter); |
| if (extension && extension->is_platform_app()) |
| return true; |
| } |