Roll src/third_party/WebKit f298044:aa8346d (svn 202628:202629)
[chromium-blink-merge.git] / chrome / browser / extensions / shared_user_script_master.cc
blob329254d716b25cd29033857295423e8ea2b61d04
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.
5 #include "chrome/browser/extensions/shared_user_script_master.h"
7 #include "chrome/browser/extensions/extension_util.h"
8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/common/extensions/manifest_handlers/content_scripts_handler.h"
10 #include "extensions/browser/extension_registry.h"
11 #include "extensions/common/host_id.h"
13 namespace extensions {
15 SharedUserScriptMaster::SharedUserScriptMaster(Profile* profile)
16 : loader_(profile,
17 HostID(),
18 true /* listen_for_extension_system_loaded */),
19 profile_(profile),
20 extension_registry_observer_(this) {
21 extension_registry_observer_.Add(ExtensionRegistry::Get(profile_));
24 SharedUserScriptMaster::~SharedUserScriptMaster() {
27 void SharedUserScriptMaster::OnExtensionLoaded(
28 content::BrowserContext* browser_context,
29 const Extension* extension) {
30 loader_.AddScripts(GetScriptsMetadata(extension));
33 void SharedUserScriptMaster::OnExtensionUnloaded(
34 content::BrowserContext* browser_context,
35 const Extension* extension,
36 UnloadedExtensionInfo::Reason reason) {
37 loader_.RemoveScripts(GetScriptsMetadata(extension));
40 const std::set<UserScript> SharedUserScriptMaster::GetScriptsMetadata(
41 const Extension* extension) {
42 bool incognito_enabled = util::IsIncognitoEnabled(extension->id(), profile_);
43 const UserScriptList& script_list =
44 ContentScriptsInfo::GetContentScripts(extension);
45 std::set<UserScript> script_set;
46 for (UserScriptList::const_iterator it = script_list.begin();
47 it != script_list.end();
48 ++it) {
49 UserScript script = *it;
50 script.set_incognito_enabled(incognito_enabled);
51 script_set.insert(script);
54 return script_set;
57 } // namespace extensions