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/renderer/user_script_set_manager.h" | 5 #include "extensions/renderer/user_script_set_manager.h" |
6 | 6 |
7 #include "components/crx_file/id_util.h" | 7 #include "components/crx_file/id_util.h" |
8 #include "content/public/renderer/render_thread.h" | 8 #include "content/public/renderer/render_thread.h" |
9 #include "extensions/common/extension_messages.h" | 9 #include "extensions/common/extension_messages.h" |
10 #include "extensions/renderer/dispatcher.h" | 10 #include "extensions/renderer/dispatcher.h" |
11 #include "extensions/renderer/script_injection.h" | 11 #include "extensions/renderer/script_injection.h" |
12 #include "extensions/renderer/user_script_set.h" | 12 #include "extensions/renderer/user_script_set.h" |
13 #include "ipc/ipc_message.h" | 13 #include "ipc/ipc_message.h" |
14 #include "ipc/ipc_message_macros.h" | 14 #include "ipc/ipc_message_macros.h" |
15 | 15 |
16 namespace extensions { | 16 namespace extensions { |
17 | 17 |
18 UserScriptSetManager::UserScriptSetManager() { | 18 UserScriptSetManager::UserScriptSetManager() |
| 19 : activity_logging_enabled_(false) { |
19 content::RenderThread::Get()->AddObserver(this); | 20 content::RenderThread::Get()->AddObserver(this); |
20 } | 21 } |
21 | 22 |
22 UserScriptSetManager::~UserScriptSetManager() { | 23 UserScriptSetManager::~UserScriptSetManager() { |
23 } | 24 } |
24 | 25 |
25 void UserScriptSetManager::AddObserver(Observer* observer) { | 26 void UserScriptSetManager::AddObserver(Observer* observer) { |
26 observers_.AddObserver(observer); | 27 observers_.AddObserver(observer); |
27 } | 28 } |
28 | 29 |
29 void UserScriptSetManager::RemoveObserver(Observer* observer) { | 30 void UserScriptSetManager::RemoveObserver(Observer* observer) { |
30 observers_.RemoveObserver(observer); | 31 observers_.RemoveObserver(observer); |
31 } | 32 } |
32 | 33 |
33 std::unique_ptr<ScriptInjection> | 34 std::unique_ptr<ScriptInjection> |
34 UserScriptSetManager::GetInjectionForDeclarativeScript( | 35 UserScriptSetManager::GetInjectionForDeclarativeScript( |
35 int script_id, | 36 int script_id, |
36 content::RenderFrame* render_frame, | 37 content::RenderFrame* render_frame, |
37 int tab_id, | 38 int tab_id, |
38 const GURL& url, | 39 const GURL& url, |
39 const std::string& extension_id) { | 40 const std::string& extension_id) { |
40 UserScriptSet* user_script_set = | 41 UserScriptSet* user_script_set = |
41 GetProgrammaticScriptsByHostID(HostID(HostID::EXTENSIONS, extension_id)); | 42 GetProgrammaticScriptsByHostID(HostID(HostID::EXTENSIONS, extension_id)); |
42 if (!user_script_set) | 43 if (!user_script_set) |
43 return std::unique_ptr<ScriptInjection>(); | 44 return std::unique_ptr<ScriptInjection>(); |
44 | 45 |
45 return user_script_set->GetDeclarativeScriptInjection( | 46 return user_script_set->GetDeclarativeScriptInjection( |
46 script_id, | 47 script_id, render_frame, tab_id, UserScript::BROWSER_DRIVEN, url, |
47 render_frame, | 48 activity_logging_enabled_); |
48 tab_id, | |
49 UserScript::BROWSER_DRIVEN, | |
50 url); | |
51 } | 49 } |
52 | 50 |
53 bool UserScriptSetManager::OnControlMessageReceived( | 51 bool UserScriptSetManager::OnControlMessageReceived( |
54 const IPC::Message& message) { | 52 const IPC::Message& message) { |
55 bool handled = true; | 53 bool handled = true; |
56 IPC_BEGIN_MESSAGE_MAP(UserScriptSetManager, message) | 54 IPC_BEGIN_MESSAGE_MAP(UserScriptSetManager, message) |
57 IPC_MESSAGE_HANDLER(ExtensionMsg_UpdateUserScripts, OnUpdateUserScripts) | 55 IPC_MESSAGE_HANDLER(ExtensionMsg_UpdateUserScripts, OnUpdateUserScripts) |
58 IPC_MESSAGE_UNHANDLED(handled = false) | 56 IPC_MESSAGE_UNHANDLED(handled = false) |
59 IPC_END_MESSAGE_MAP() | 57 IPC_END_MESSAGE_MAP() |
60 return handled; | 58 return handled; |
61 } | 59 } |
62 | 60 |
63 void UserScriptSetManager::GetAllInjections( | 61 void UserScriptSetManager::GetAllInjections( |
64 std::vector<std::unique_ptr<ScriptInjection>>* injections, | 62 std::vector<std::unique_ptr<ScriptInjection>>* injections, |
65 content::RenderFrame* render_frame, | 63 content::RenderFrame* render_frame, |
66 int tab_id, | 64 int tab_id, |
67 UserScript::RunLocation run_location) { | 65 UserScript::RunLocation run_location) { |
68 static_scripts_.GetInjections(injections, render_frame, tab_id, run_location); | 66 static_scripts_.GetInjections(injections, render_frame, tab_id, run_location, |
| 67 activity_logging_enabled_); |
69 for (UserScriptSetMap::iterator it = programmatic_scripts_.begin(); | 68 for (UserScriptSetMap::iterator it = programmatic_scripts_.begin(); |
70 it != programmatic_scripts_.end(); | 69 it != programmatic_scripts_.end(); |
71 ++it) { | 70 ++it) { |
72 it->second->GetInjections(injections, render_frame, tab_id, run_location); | 71 it->second->GetInjections(injections, render_frame, tab_id, run_location, |
| 72 activity_logging_enabled_); |
73 } | 73 } |
74 } | 74 } |
75 | 75 |
76 void UserScriptSetManager::GetAllActiveExtensionIds( | 76 void UserScriptSetManager::GetAllActiveExtensionIds( |
77 std::set<std::string>* ids) const { | 77 std::set<std::string>* ids) const { |
78 DCHECK(ids); | 78 DCHECK(ids); |
79 static_scripts_.GetActiveExtensionIds(ids); | 79 static_scripts_.GetActiveExtensionIds(ids); |
80 for (UserScriptSetMap::const_iterator it = programmatic_scripts_.begin(); | 80 for (UserScriptSetMap::const_iterator it = programmatic_scripts_.begin(); |
81 it != programmatic_scripts_.end(); | 81 it != programmatic_scripts_.end(); |
82 ++it) { | 82 ++it) { |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 *effective_hosts, | 150 *effective_hosts, |
151 whitelisted_only)) { | 151 whitelisted_only)) { |
152 FOR_EACH_OBSERVER( | 152 FOR_EACH_OBSERVER( |
153 Observer, | 153 Observer, |
154 observers_, | 154 observers_, |
155 OnUserScriptsUpdated(*effective_hosts, scripts->scripts())); | 155 OnUserScriptsUpdated(*effective_hosts, scripts->scripts())); |
156 } | 156 } |
157 } | 157 } |
158 | 158 |
159 } // namespace extensions | 159 } // namespace extensions |
OLD | NEW |