| 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 "content/public/common/url_constants.h" | 7 #include "content/public/common/url_constants.h" |
| 8 #include "content/public/renderer/render_thread.h" | 8 #include "content/public/renderer/render_thread.h" |
| 9 #include "extensions/common/extension.h" | 9 #include "extensions/common/extension.h" |
| 10 #include "extensions/common/extension_messages.h" | 10 #include "extensions/common/extension_messages.h" |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 const Extension* extension = extensions_->GetByID((*iter)->extension_id()); | 72 const Extension* extension = extensions_->GetByID((*iter)->extension_id()); |
| 73 if (!extension) | 73 if (!extension) |
| 74 continue; | 74 continue; |
| 75 scoped_ptr<ScriptInjection> injection = GetInjectionForScript( | 75 scoped_ptr<ScriptInjection> injection = GetInjectionForScript( |
| 76 *iter, web_frame, tab_id, run_location, document_url, extension); | 76 *iter, web_frame, tab_id, run_location, document_url, extension); |
| 77 if (injection.get()) | 77 if (injection.get()) |
| 78 injections->push_back(injection.release()); | 78 injections->push_back(injection.release()); |
| 79 } | 79 } |
| 80 } | 80 } |
| 81 | 81 |
| 82 bool UserScriptSet::OnControlMessageReceived( | 82 bool UserScriptSet::OnUpdateUserScripts( |
| 83 const IPC::Message& message) { | |
| 84 bool handled = true; | |
| 85 IPC_BEGIN_MESSAGE_MAP(UserScriptSet, message) | |
| 86 IPC_MESSAGE_HANDLER(ExtensionMsg_UpdateUserScripts, OnUpdateUserScripts) | |
| 87 IPC_MESSAGE_UNHANDLED(handled = false) | |
| 88 IPC_END_MESSAGE_MAP() | |
| 89 return handled; | |
| 90 } | |
| 91 | |
| 92 void UserScriptSet::OnUpdateUserScripts( | |
| 93 base::SharedMemoryHandle shared_memory, | 83 base::SharedMemoryHandle shared_memory, |
| 94 const std::set<std::string>& changed_extensions) { | 84 const std::set<std::string>& changed_extensions) { |
| 95 if (!base::SharedMemory::IsHandleValid(shared_memory)) { | 85 if (!base::SharedMemory::IsHandleValid(shared_memory)) { |
| 96 NOTREACHED() << "Bad scripts handle"; | 86 NOTREACHED() << "Bad scripts handle"; |
| 97 return; | 87 return false; |
| 98 } | 88 } |
| 99 | 89 |
| 100 for (std::set<std::string>::const_iterator iter = changed_extensions.begin(); | 90 for (std::set<std::string>::const_iterator iter = changed_extensions.begin(); |
| 101 iter != changed_extensions.end(); | 91 iter != changed_extensions.end(); |
| 102 ++iter) { | 92 ++iter) { |
| 103 if (!Extension::IdIsValid(*iter)) { | 93 if (!Extension::IdIsValid(*iter)) { |
| 104 NOTREACHED() << "Invalid extension id: " << *iter; | 94 NOTREACHED() << "Invalid extension id: " << *iter; |
| 105 return; | 95 return false; |
| 106 } | 96 } |
| 107 } | 97 } |
| 108 | 98 |
| 109 if (UpdateScripts(shared_memory)) { | 99 if (!UpdateScripts(shared_memory)) { |
| 110 FOR_EACH_OBSERVER(Observer, | 100 return false; |
| 111 observers_, | |
| 112 OnUserScriptsUpdated(changed_extensions, scripts_.get())); | |
| 113 } | 101 } |
| 102 |
| 103 FOR_EACH_OBSERVER(Observer, |
| 104 observers_, |
| 105 OnUserScriptsUpdated(changed_extensions, scripts_.get())); |
| 106 return true; |
| 114 } | 107 } |
| 115 | 108 |
| 116 bool UserScriptSet::UpdateScripts( | 109 bool UserScriptSet::UpdateScripts( |
| 117 base::SharedMemoryHandle shared_memory) { | 110 base::SharedMemoryHandle shared_memory) { |
| 118 bool only_inject_incognito = | 111 bool only_inject_incognito = |
| 119 ExtensionsRendererClient::Get()->IsIncognitoProcess(); | 112 ExtensionsRendererClient::Get()->IsIncognitoProcess(); |
| 120 | 113 |
| 121 // Create the shared memory object (read only). | 114 // Create the shared memory object (read only). |
| 122 shared_memory_.reset(new base::SharedMemory(shared_memory, true)); | 115 shared_memory_.reset(new base::SharedMemory(shared_memory, true)); |
| 123 if (!shared_memory_.get()) | 116 if (!shared_memory_.get()) |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 scoped_ptr<ScriptInjector>(new UserScriptInjector(script, this)), | 203 scoped_ptr<ScriptInjector>(new UserScriptInjector(script, this)), |
| 211 web_frame, | 204 web_frame, |
| 212 extension->id(), | 205 extension->id(), |
| 213 run_location, | 206 run_location, |
| 214 tab_id)); | 207 tab_id)); |
| 215 } | 208 } |
| 216 return injection.Pass(); | 209 return injection.Pass(); |
| 217 } | 210 } |
| 218 | 211 |
| 219 } // namespace extensions | 212 } // namespace extensions |
| OLD | NEW |