| 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.h" | 5 #include "extensions/renderer/user_script_set.h" |
| 6 | 6 |
| 7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
| 8 #include "content/public/common/url_constants.h" | 8 #include "content/public/common/url_constants.h" |
| 9 #include "content/public/renderer/render_thread.h" | 9 #include "content/public/renderer/render_thread.h" |
| 10 #include "extensions/common/extension.h" | 10 #include "extensions/common/extension.h" |
| 11 #include "extensions/common/extension_set.h" | 11 #include "extensions/common/extension_set.h" |
| 12 #include "extensions/common/extensions_client.h" |
| 12 #include "extensions/common/permissions/permissions_data.h" | 13 #include "extensions/common/permissions/permissions_data.h" |
| 13 #include "extensions/renderer/extension_injection_host.h" | 14 #include "extensions/renderer/extension_injection_host.h" |
| 14 #include "extensions/renderer/extensions_renderer_client.h" | 15 #include "extensions/renderer/extensions_renderer_client.h" |
| 15 #include "extensions/renderer/injection_host.h" | 16 #include "extensions/renderer/injection_host.h" |
| 16 #include "extensions/renderer/script_context.h" | 17 #include "extensions/renderer/script_context.h" |
| 17 #include "extensions/renderer/script_injection.h" | 18 #include "extensions/renderer/script_injection.h" |
| 18 #include "extensions/renderer/user_script_injector.h" | 19 #include "extensions/renderer/user_script_injector.h" |
| 19 #include "extensions/renderer/web_ui_injection_host.h" | 20 #include "extensions/renderer/web_ui_injection_host.h" |
| 20 #include "third_party/WebKit/public/web/WebDocument.h" | 21 #include "third_party/WebKit/public/web/WebDocument.h" |
| 21 #include "third_party/WebKit/public/web/WebFrame.h" | 22 #include "third_party/WebKit/public/web/WebFrame.h" |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 tab_id, | 80 tab_id, |
| 80 run_location, | 81 run_location, |
| 81 document_url, | 82 document_url, |
| 82 false /* is_declarative */); | 83 false /* is_declarative */); |
| 83 if (injection.get()) | 84 if (injection.get()) |
| 84 injections->push_back(injection.release()); | 85 injections->push_back(injection.release()); |
| 85 } | 86 } |
| 86 } | 87 } |
| 87 | 88 |
| 88 bool UserScriptSet::UpdateUserScripts(base::SharedMemoryHandle shared_memory, | 89 bool UserScriptSet::UpdateUserScripts(base::SharedMemoryHandle shared_memory, |
| 89 const std::set<HostID>& changed_hosts) { | 90 const std::set<HostID>& changed_hosts, |
| 91 bool whitelisted_only) { |
| 90 bool only_inject_incognito = | 92 bool only_inject_incognito = |
| 91 ExtensionsRendererClient::Get()->IsIncognitoProcess(); | 93 ExtensionsRendererClient::Get()->IsIncognitoProcess(); |
| 92 | 94 |
| 93 // Create the shared memory object (read only). | 95 // Create the shared memory object (read only). |
| 94 shared_memory_.reset(new base::SharedMemory(shared_memory, true)); | 96 shared_memory_.reset(new base::SharedMemory(shared_memory, true)); |
| 95 if (!shared_memory_.get()) | 97 if (!shared_memory_.get()) |
| 96 return false; | 98 return false; |
| 97 | 99 |
| 98 // First get the size of the memory block. | 100 // First get the size of the memory block. |
| 99 if (!shared_memory_->Map(sizeof(Pickle::Header))) | 101 if (!shared_memory_->Map(sizeof(Pickle::Header))) |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 const char* body = NULL; | 135 const char* body = NULL; |
| 134 int body_length = 0; | 136 int body_length = 0; |
| 135 CHECK(iter.ReadData(&body, &body_length)); | 137 CHECK(iter.ReadData(&body, &body_length)); |
| 136 script->css_scripts()[j].set_external_content( | 138 script->css_scripts()[j].set_external_content( |
| 137 base::StringPiece(body, body_length)); | 139 base::StringPiece(body, body_length)); |
| 138 } | 140 } |
| 139 | 141 |
| 140 if (only_inject_incognito && !script->is_incognito_enabled()) | 142 if (only_inject_incognito && !script->is_incognito_enabled()) |
| 141 continue; // This script shouldn't run in an incognito tab. | 143 continue; // This script shouldn't run in an incognito tab. |
| 142 | 144 |
| 145 if (whitelisted_only) { |
| 146 const ExtensionsClient::ScriptingWhitelist& whitelist = |
| 147 ExtensionsClient::Get()->GetScriptingWhitelist(); |
| 148 if (std::find(whitelist.begin(), whitelist.end(), |
| 149 script->extension_id()) == whitelist.end()) { |
| 150 continue; |
| 151 } |
| 152 } |
| 153 |
| 143 scripts_.push_back(script.release()); | 154 scripts_.push_back(script.release()); |
| 144 } | 155 } |
| 145 | 156 |
| 146 FOR_EACH_OBSERVER(Observer, | 157 FOR_EACH_OBSERVER(Observer, |
| 147 observers_, | 158 observers_, |
| 148 OnUserScriptsUpdated(changed_hosts, scripts_.get())); | 159 OnUserScriptsUpdated(changed_hosts, scripts_.get())); |
| 149 return true; | 160 return true; |
| 150 } | 161 } |
| 151 | 162 |
| 152 scoped_ptr<ScriptInjection> UserScriptSet::GetDeclarativeScriptInjection( | 163 scoped_ptr<ScriptInjection> UserScriptSet::GetDeclarativeScriptInjection( |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 injector.Pass(), | 240 injector.Pass(), |
| 230 web_frame->toWebLocalFrame(), | 241 web_frame->toWebLocalFrame(), |
| 231 injection_host.Pass(), | 242 injection_host.Pass(), |
| 232 run_location, | 243 run_location, |
| 233 tab_id)); | 244 tab_id)); |
| 234 } | 245 } |
| 235 return injection.Pass(); | 246 return injection.Pass(); |
| 236 } | 247 } |
| 237 | 248 |
| 238 } // namespace extensions | 249 } // namespace extensions |
| OLD | NEW |