Chromium Code Reviews| 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 "chrome/browser/extensions/shared_user_script_master.h" | |
| 6 | |
| 7 #include "chrome/browser/extensions/extension_util.h" | |
| 8 #include "chrome/browser/profiles/profile.h" | |
|
Devlin
2014/08/06 15:59:25
Don't need this.
Mark Dittmer
2014/08/06 22:08:18
Do too :-P For profile_.
Devlin
2014/08/07 15:46:31
We never really use profile_, so just knowing that
Mark Dittmer
2014/08/11 14:08:04
Acknowledged.
| |
| 9 #include "chrome/common/extensions/manifest_handlers/content_scripts_handler.h" | |
| 10 #include "extensions/browser/extension_registry.h" | |
| 11 | |
| 12 namespace extensions { | |
| 13 | |
| 14 SharedUserScriptMaster::SharedUserScriptMaster(Profile* profile) | |
| 15 : loader_(profile, | |
| 16 std::string() /* owner_extension_id */, | |
| 17 true /* listen_for_extension_system_loaded */), | |
| 18 profile_(profile), | |
| 19 extension_registry_observer_(this) { | |
| 20 extension_registry_observer_.Add(ExtensionRegistry::Get(profile_)); | |
| 21 } | |
| 22 | |
| 23 SharedUserScriptMaster::~SharedUserScriptMaster() { | |
| 24 } | |
| 25 | |
| 26 void SharedUserScriptMaster::OnExtensionLoaded( | |
| 27 content::BrowserContext* browser_context, | |
| 28 const Extension* extension) { | |
| 29 loader_.AddScripts(GetScriptsMetadata(extension)); | |
| 30 } | |
| 31 | |
| 32 void SharedUserScriptMaster::OnExtensionUnloaded( | |
| 33 content::BrowserContext* browser_context, | |
| 34 const Extension* extension, | |
| 35 UnloadedExtensionInfo::Reason reason) { | |
| 36 loader_.RemoveScripts(GetScriptsMetadata(extension)); | |
| 37 loader_.ClearExtensionInfo(extension->id()); | |
| 38 scripts_metadata_.erase(extension->id()); | |
| 39 } | |
| 40 | |
| 41 const std::set<UserScript>& SharedUserScriptMaster::GetScriptsMetadata( | |
| 42 const Extension* extension) { | |
| 43 const ExtensionId& id = extension->id(); | |
| 44 std::map<ExtensionId, std::set<UserScript> >::const_iterator iter = | |
| 45 scripts_metadata_.find(id); | |
| 46 if (iter != scripts_metadata_.end()) | |
| 47 return iter->second; | |
| 48 | |
| 49 scripts_metadata_[id] = std::set<UserScript>(); | |
|
Devlin
2014/08/06 15:59:25
I'm somewhat dubious of the benefit of storing all
Mark Dittmer
2014/08/06 22:08:18
Got rid of scripts_metadata_, but I am leaving the
Devlin
2014/08/07 15:46:31
Works for me.
Mark Dittmer
2014/08/11 14:08:04
Acknowledged.
| |
| 50 bool incognito_enabled = util::IsIncognitoEnabled(id, profile_); | |
| 51 const UserScriptList& fetched_scripts = | |
| 52 ContentScriptsInfo::GetContentScripts(extension); | |
| 53 std::set<UserScript>& stored_scripts = scripts_metadata_[id]; | |
| 54 for (UserScriptList::const_iterator it = fetched_scripts.begin(); | |
| 55 it != fetched_scripts.end(); | |
| 56 ++it) { | |
| 57 UserScript script = *it; | |
| 58 script.set_incognito_enabled(incognito_enabled); | |
| 59 stored_scripts.insert(script); | |
| 60 } | |
| 61 | |
| 62 return stored_scripts; | |
| 63 } | |
| 64 | |
| 65 } // namespace extensions | |
| OLD | NEW |