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 #include "third_party/WebKit/public/web/WebFrame.h" | 15 #include "third_party/WebKit/public/web/WebFrame.h" |
16 | 16 |
17 namespace extensions { | 17 namespace extensions { |
18 | 18 |
19 UserScriptSetManager::UserScriptSetManager(const ExtensionSet* extensions) | 19 UserScriptSetManager::UserScriptSetManager(const ExtensionSet* extensions) |
20 : static_scripts_(extensions), extensions_(extensions) { | 20 : static_scripts_(extensions), |
| 21 is_in_guest_render_process_(false), |
| 22 extensions_(extensions) { |
21 content::RenderThread::Get()->AddObserver(this); | 23 content::RenderThread::Get()->AddObserver(this); |
22 } | 24 } |
23 | 25 |
24 UserScriptSetManager::~UserScriptSetManager() { | 26 UserScriptSetManager::~UserScriptSetManager() { |
25 } | 27 } |
26 | 28 |
27 void UserScriptSetManager::AddObserver(Observer* observer) { | 29 void UserScriptSetManager::AddObserver(Observer* observer) { |
28 observers_.AddObserver(observer); | 30 observers_.AddObserver(observer); |
29 } | 31 } |
30 | 32 |
(...skipping 29 matching lines...) Expand all Loading... |
60 IPC_MESSAGE_UNHANDLED(handled = false) | 62 IPC_MESSAGE_UNHANDLED(handled = false) |
61 IPC_END_MESSAGE_MAP() | 63 IPC_END_MESSAGE_MAP() |
62 return handled; | 64 return handled; |
63 } | 65 } |
64 | 66 |
65 void UserScriptSetManager::GetAllInjections( | 67 void UserScriptSetManager::GetAllInjections( |
66 ScopedVector<ScriptInjection>* injections, | 68 ScopedVector<ScriptInjection>* injections, |
67 blink::WebFrame* web_frame, | 69 blink::WebFrame* web_frame, |
68 int tab_id, | 70 int tab_id, |
69 UserScript::RunLocation run_location) { | 71 UserScript::RunLocation run_location) { |
70 static_scripts_.GetInjections(injections, web_frame, tab_id, run_location); | 72 static_scripts_.GetInjections(injections, web_frame, tab_id, run_location, |
| 73 is_in_guest_render_process_); |
71 for (UserScriptSetMap::iterator it = programmatic_scripts_.begin(); | 74 for (UserScriptSetMap::iterator it = programmatic_scripts_.begin(); |
72 it != programmatic_scripts_.end(); | 75 it != programmatic_scripts_.end(); |
73 ++it) { | 76 ++it) { |
74 it->second->GetInjections(injections, web_frame, tab_id, run_location); | 77 it->second->GetInjections(injections, web_frame, tab_id, run_location, |
| 78 is_in_guest_render_process_); |
75 } | 79 } |
76 } | 80 } |
77 | 81 |
78 void UserScriptSetManager::GetAllActiveExtensionIds( | 82 void UserScriptSetManager::GetAllActiveExtensionIds( |
79 std::set<std::string>* ids) const { | 83 std::set<std::string>* ids) const { |
80 DCHECK(ids); | 84 DCHECK(ids); |
81 static_scripts_.GetActiveExtensionIds(ids); | 85 static_scripts_.GetActiveExtensionIds(ids); |
82 for (UserScriptSetMap::const_iterator it = programmatic_scripts_.begin(); | 86 for (UserScriptSetMap::const_iterator it = programmatic_scripts_.begin(); |
83 it != programmatic_scripts_.end(); | 87 it != programmatic_scripts_.end(); |
84 ++it) { | 88 ++it) { |
85 it->second->GetActiveExtensionIds(ids); | 89 it->second->GetActiveExtensionIds(ids); |
86 } | 90 } |
87 } | 91 } |
88 | 92 |
89 UserScriptSet* UserScriptSetManager::GetProgrammaticScriptsByHostID( | 93 UserScriptSet* UserScriptSetManager::GetProgrammaticScriptsByHostID( |
90 const HostID& host_id) { | 94 const HostID& host_id) { |
91 UserScriptSetMap::const_iterator it = programmatic_scripts_.find(host_id); | 95 UserScriptSetMap::const_iterator it = programmatic_scripts_.find(host_id); |
92 return it != programmatic_scripts_.end() ? it->second.get() : NULL; | 96 return it != programmatic_scripts_.end() ? it->second.get() : NULL; |
93 } | 97 } |
94 | 98 |
95 void UserScriptSetManager::OnUpdateUserScripts( | 99 void UserScriptSetManager::OnUpdateUserScripts( |
96 base::SharedMemoryHandle shared_memory, | 100 base::SharedMemoryHandle shared_memory, |
97 const HostID& host_id, | 101 const HostID& host_id, |
98 const std::set<HostID>& changed_hosts) { | 102 const std::set<HostID>& changed_hosts, |
| 103 bool is_to_guest_render_process) { |
| 104 is_in_guest_render_process_ = is_to_guest_render_process; |
| 105 |
99 if (!base::SharedMemory::IsHandleValid(shared_memory)) { | 106 if (!base::SharedMemory::IsHandleValid(shared_memory)) { |
100 NOTREACHED() << "Bad scripts handle"; | 107 NOTREACHED() << "Bad scripts handle"; |
101 return; | 108 return; |
102 } | 109 } |
103 | 110 |
104 for (const HostID& host_id : changed_hosts) { | 111 for (const HostID& host_id : changed_hosts) { |
105 if (host_id.type() == HostID::EXTENSIONS && | 112 if (host_id.type() == HostID::EXTENSIONS && |
106 !crx_file::id_util::IdIsValid(host_id.id())) { | 113 !crx_file::id_util::IdIsValid(host_id.id())) { |
107 NOTREACHED() << "Invalid extension id: " << host_id.id(); | 114 NOTREACHED() << "Invalid extension id: " << host_id.id(); |
108 return; | 115 return; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 | 155 |
149 if (scripts->UpdateUserScripts(shared_memory, *effective_hosts)) { | 156 if (scripts->UpdateUserScripts(shared_memory, *effective_hosts)) { |
150 FOR_EACH_OBSERVER( | 157 FOR_EACH_OBSERVER( |
151 Observer, | 158 Observer, |
152 observers_, | 159 observers_, |
153 OnUserScriptsUpdated(*effective_hosts, scripts->scripts())); | 160 OnUserScriptsUpdated(*effective_hosts, scripts->scripts())); |
154 } | 161 } |
155 } | 162 } |
156 | 163 |
157 } // namespace extensions | 164 } // namespace extensions |
OLD | NEW |