Chromium Code Reviews| 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 18 matching lines...) Expand all Loading... | |
| 29 data_source_url.spec()); | 29 data_source_url.spec()); |
| 30 } | 30 } |
| 31 | 31 |
| 32 return data_source_url; | 32 return data_source_url; |
| 33 } | 33 } |
| 34 | 34 |
| 35 } // namespace | 35 } // namespace |
| 36 | 36 |
| 37 UserScriptSet::UserScriptSet(const ExtensionSet* extensions) | 37 UserScriptSet::UserScriptSet(const ExtensionSet* extensions) |
| 38 : extensions_(extensions) { | 38 : extensions_(extensions) { |
| 39 content::RenderThread::Get()->AddObserver(this); | |
| 40 } | 39 } |
| 41 | 40 |
| 42 UserScriptSet::~UserScriptSet() { | 41 UserScriptSet::~UserScriptSet() { |
| 43 } | 42 } |
| 44 | 43 |
| 45 void UserScriptSet::AddObserver(Observer* observer) { | 44 void UserScriptSet::AddObserver(Observer* observer) { |
| 46 observers_.AddObserver(observer); | 45 observers_.AddObserver(observer); |
| 47 } | 46 } |
| 48 | 47 |
| 49 void UserScriptSet::RemoveObserver(Observer* observer) { | 48 void UserScriptSet::RemoveObserver(Observer* observer) { |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 72 const Extension* extension = extensions_->GetByID((*iter)->extension_id()); | 71 const Extension* extension = extensions_->GetByID((*iter)->extension_id()); |
| 73 if (!extension) | 72 if (!extension) |
| 74 continue; | 73 continue; |
| 75 scoped_ptr<ScriptInjection> injection = GetInjectionForScript( | 74 scoped_ptr<ScriptInjection> injection = GetInjectionForScript( |
| 76 *iter, web_frame, tab_id, run_location, document_url, extension); | 75 *iter, web_frame, tab_id, run_location, document_url, extension); |
| 77 if (injection.get()) | 76 if (injection.get()) |
| 78 injections->push_back(injection.release()); | 77 injections->push_back(injection.release()); |
| 79 } | 78 } |
| 80 } | 79 } |
| 81 | 80 |
| 82 bool UserScriptSet::OnControlMessageReceived( | 81 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, | 82 base::SharedMemoryHandle shared_memory, |
| 94 const std::set<std::string>& changed_extensions) { | 83 const std::set<std::string>& changed_extensions) { |
| 95 if (!base::SharedMemory::IsHandleValid(shared_memory)) { | 84 if (!base::SharedMemory::IsHandleValid(shared_memory)) { |
| 96 NOTREACHED() << "Bad scripts handle"; | 85 NOTREACHED() << "Bad scripts handle"; |
| 97 return; | 86 return false; |
| 98 } | 87 } |
| 99 | 88 |
| 100 for (std::set<std::string>::const_iterator iter = changed_extensions.begin(); | 89 for (std::set<std::string>::const_iterator iter = changed_extensions.begin(); |
| 101 iter != changed_extensions.end(); | 90 iter != changed_extensions.end(); |
| 102 ++iter) { | 91 ++iter) { |
| 103 if (!Extension::IdIsValid(*iter)) { | 92 if (!Extension::IdIsValid(*iter)) { |
| 104 NOTREACHED() << "Invalid extension id: " << *iter; | 93 NOTREACHED() << "Invalid extension id: " << *iter; |
| 105 return; | 94 return false; |
| 106 } | 95 } |
| 107 } | 96 } |
| 108 | 97 |
| 109 if (UpdateScripts(shared_memory)) { | 98 if (!UpdateScripts(shared_memory)) { |
|
Devlin
2014/07/28 18:15:27
nit: no brackets on single-line ifs.
Mark Dittmer
2014/07/28 22:21:28
Done.
| |
| 110 FOR_EACH_OBSERVER(Observer, | 99 return false; |
| 111 observers_, | |
| 112 OnUserScriptsUpdated(changed_extensions, scripts_.get())); | |
| 113 } | 100 } |
| 101 | |
| 102 FOR_EACH_OBSERVER(Observer, | |
| 103 observers_, | |
| 104 OnUserScriptsUpdated(changed_extensions, scripts_.get())); | |
|
Jeffrey Yasskin
2014/07/28 17:47:16
I wonder if it'll make sense to remove OnUserScrip
Mark Dittmer
2014/07/28 22:21:28
Acknowledged.
| |
| 105 return true; | |
| 114 } | 106 } |
| 115 | 107 |
| 116 bool UserScriptSet::UpdateScripts( | 108 bool UserScriptSet::UpdateScripts( |
| 117 base::SharedMemoryHandle shared_memory) { | 109 base::SharedMemoryHandle shared_memory) { |
| 118 bool only_inject_incognito = | 110 bool only_inject_incognito = |
| 119 ExtensionsRendererClient::Get()->IsIncognitoProcess(); | 111 ExtensionsRendererClient::Get()->IsIncognitoProcess(); |
| 120 | 112 |
| 121 // Create the shared memory object (read only). | 113 // Create the shared memory object (read only). |
| 122 shared_memory_.reset(new base::SharedMemory(shared_memory, true)); | 114 shared_memory_.reset(new base::SharedMemory(shared_memory, true)); |
| 123 if (!shared_memory_.get()) | 115 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)), | 202 scoped_ptr<ScriptInjector>(new UserScriptInjector(script, this)), |
| 211 web_frame, | 203 web_frame, |
| 212 extension->id(), | 204 extension->id(), |
| 213 run_location, | 205 run_location, |
| 214 tab_id)); | 206 tab_id)); |
| 215 } | 207 } |
| 216 return injection.Pass(); | 208 return injection.Pass(); |
| 217 } | 209 } |
| 218 | 210 |
| 219 } // namespace extensions | 211 } // namespace extensions |
| OLD | NEW |