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 "chrome/browser/extensions/shared_user_script_master.h" | 5 #include "chrome/browser/extensions/shared_user_script_master.h" |
6 | 6 |
7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
9 #include "chrome/common/extensions/manifest_handlers/content_scripts_handler.h" | 9 #include "chrome/common/extensions/manifest_handlers/content_scripts_handler.h" |
10 #include "extensions/browser/extension_registry.h" | 10 #include "extensions/browser/extension_registry.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 | 27 |
28 void SharedUserScriptMaster::OnExtensionLoaded( | 28 void SharedUserScriptMaster::OnExtensionLoaded( |
29 content::BrowserContext* browser_context, | 29 content::BrowserContext* browser_context, |
30 const Extension* extension) { | 30 const Extension* extension) { |
31 loader_.AddScripts(GetScriptsMetadata(extension)); | 31 loader_.AddScripts(GetScriptsMetadata(extension)); |
32 } | 32 } |
33 | 33 |
34 void SharedUserScriptMaster::OnExtensionUnloaded( | 34 void SharedUserScriptMaster::OnExtensionUnloaded( |
35 content::BrowserContext* browser_context, | 35 content::BrowserContext* browser_context, |
36 const Extension* extension, | 36 const Extension* extension, |
37 UnloadedExtensionInfo::Reason reason) { | 37 UnloadedExtensionReason reason) { |
38 const UserScriptList& script_list = | 38 const UserScriptList& script_list = |
39 ContentScriptsInfo::GetContentScripts(extension); | 39 ContentScriptsInfo::GetContentScripts(extension); |
40 std::set<UserScriptIDPair> scripts_to_remove; | 40 std::set<UserScriptIDPair> scripts_to_remove; |
41 for (const std::unique_ptr<UserScript>& script : script_list) | 41 for (const std::unique_ptr<UserScript>& script : script_list) |
42 scripts_to_remove.insert(UserScriptIDPair(script->id(), script->host_id())); | 42 scripts_to_remove.insert(UserScriptIDPair(script->id(), script->host_id())); |
43 loader_.RemoveScripts(scripts_to_remove); | 43 loader_.RemoveScripts(scripts_to_remove); |
44 } | 44 } |
45 | 45 |
46 std::unique_ptr<UserScriptList> SharedUserScriptMaster::GetScriptsMetadata( | 46 std::unique_ptr<UserScriptList> SharedUserScriptMaster::GetScriptsMetadata( |
47 const Extension* extension) { | 47 const Extension* extension) { |
48 bool incognito_enabled = util::IsIncognitoEnabled(extension->id(), profile_); | 48 bool incognito_enabled = util::IsIncognitoEnabled(extension->id(), profile_); |
49 const UserScriptList& script_list = | 49 const UserScriptList& script_list = |
50 ContentScriptsInfo::GetContentScripts(extension); | 50 ContentScriptsInfo::GetContentScripts(extension); |
51 std::unique_ptr<UserScriptList> script_vector(new UserScriptList()); | 51 std::unique_ptr<UserScriptList> script_vector(new UserScriptList()); |
52 script_vector->reserve(script_list.size()); | 52 script_vector->reserve(script_list.size()); |
53 for (const std::unique_ptr<UserScript>& script : script_list) { | 53 for (const std::unique_ptr<UserScript>& script : script_list) { |
54 std::unique_ptr<UserScript> script_copy = | 54 std::unique_ptr<UserScript> script_copy = |
55 UserScript::CopyMetadataFrom(*script); | 55 UserScript::CopyMetadataFrom(*script); |
56 script_copy->set_incognito_enabled(incognito_enabled); | 56 script_copy->set_incognito_enabled(incognito_enabled); |
57 script_vector->push_back(std::move(script_copy)); | 57 script_vector->push_back(std::move(script_copy)); |
58 } | 58 } |
59 return script_vector; | 59 return script_vector; |
60 } | 60 } |
61 | 61 |
62 } // namespace extensions | 62 } // namespace extensions |
OLD | NEW |