| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "extensions/renderer/user_script_set_manager.h" |
| 6 |
| 7 #include "content/public/renderer/render_thread.h" |
| 8 #include "extensions/common/extension_messages.h" |
| 9 #include "extensions/renderer/dispatcher.h" |
| 10 #include "extensions/renderer/user_script_set.h" |
| 11 #include "ipc/ipc_message.h" |
| 12 #include "ipc/ipc_message_macros.h" |
| 13 #include "third_party/WebKit/public/web/WebFrame.h" |
| 14 |
| 15 namespace extensions { |
| 16 |
| 17 UserScriptSetManager::UserScriptSetManager(const ExtensionSet* extensions) |
| 18 : static_scripts_(new UserScriptSet(extensions)), extensions_(extensions) { |
| 19 content::RenderThread::Get()->AddObserver(this); |
| 20 } |
| 21 |
| 22 UserScriptSetManager::~UserScriptSetManager() { |
| 23 } |
| 24 |
| 25 void UserScriptSetManager::AddObserver(Observer* observer) { |
| 26 observers_.AddObserver(observer); |
| 27 } |
| 28 |
| 29 void UserScriptSetManager::RemoveObserver(Observer* observer) { |
| 30 observers_.RemoveObserver(observer); |
| 31 } |
| 32 |
| 33 bool UserScriptSetManager::OnControlMessageReceived( |
| 34 const IPC::Message& message) { |
| 35 bool handled = true; |
| 36 IPC_BEGIN_MESSAGE_MAP(UserScriptSetManager, message) |
| 37 IPC_MESSAGE_HANDLER(ExtensionMsg_UpdateUserScripts, OnUpdateUserScripts) |
| 38 IPC_MESSAGE_UNHANDLED(handled = false) |
| 39 IPC_END_MESSAGE_MAP() |
| 40 return handled; |
| 41 } |
| 42 |
| 43 const linked_ptr<UserScriptSet> UserScriptSetManager::ProgrammaticScripts( |
| 44 const ExtensionId& extension_id) { |
| 45 UserScriptSetMap::const_iterator it = |
| 46 programmatic_scripts_.find(extension_id); |
| 47 if (it == programmatic_scripts_.end()) { |
| 48 return linked_ptr<UserScriptSet>(); |
| 49 } |
| 50 |
| 51 return it->second; |
| 52 } |
| 53 |
| 54 void UserScriptSetManager::GetAllInjections( |
| 55 ScopedVector<ScriptInjection>* injections, |
| 56 blink::WebFrame* web_frame, |
| 57 int tab_id, |
| 58 UserScript::RunLocation run_location) { |
| 59 static_scripts_->GetInjections(injections, web_frame, tab_id, run_location); |
| 60 for (UserScriptSetMap::iterator it = programmatic_scripts_.begin(); |
| 61 it != programmatic_scripts_.end(); |
| 62 ++it) { |
| 63 it->second->GetInjections(injections, web_frame, tab_id, run_location); |
| 64 } |
| 65 } |
| 66 |
| 67 void UserScriptSetManager::GetAllActiveExtensionIds( |
| 68 std::set<std::string>* ids) const { |
| 69 static_scripts_->GetActiveExtensionIds(ids); |
| 70 for (UserScriptSetMap::const_iterator it = programmatic_scripts_.begin(); |
| 71 it != programmatic_scripts_.end(); |
| 72 ++it) { |
| 73 it->second->GetActiveExtensionIds(ids); |
| 74 } |
| 75 } |
| 76 |
| 77 void UserScriptSetManager::OnUpdateUserScripts( |
| 78 base::SharedMemoryHandle shared_memory, |
| 79 const ExtensionId& extension_id, |
| 80 const std::set<std::string>& changed_extensions) { |
| 81 UserScriptSet* scripts = NULL; |
| 82 if (extension_id != "") { |
| 83 if (programmatic_scripts_.find(extension_id) != |
| 84 programmatic_scripts_.end()) { |
| 85 scripts = new UserScriptSet(extensions_); |
| 86 programmatic_scripts_[extension_id] = make_linked_ptr(scripts); |
| 87 } else { |
| 88 scripts = programmatic_scripts_[extension_id].get(); |
| 89 } |
| 90 } else { |
| 91 scripts = static_scripts_.get(); |
| 92 } |
| 93 if (scripts && |
| 94 scripts->OnUpdateUserScripts(shared_memory, changed_extensions)) { |
| 95 FOR_EACH_OBSERVER( |
| 96 Observer, |
| 97 observers_, |
| 98 OnUserScriptsUpdated(changed_extensions, scripts->scripts_.get())); |
| 99 } |
| 100 } |
| 101 |
| 102 } // namespace extensions |
| OLD | NEW |