| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/renderer/pepper/pepper_plugin_registry.h" | 5 #include "content/renderer/pepper/pepper_plugin_registry.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "content/common/pepper_plugin_list.h" | 8 #include "content/common/pepper_plugin_list.h" |
| 9 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" | 9 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" |
| 10 #include "content/renderer/pepper/plugin_module.h" | 10 #include "content/renderer/pepper/plugin_module.h" |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 live_modules_[path] = module; | 75 live_modules_[path] = module; |
| 76 } | 76 } |
| 77 | 77 |
| 78 void PepperPluginRegistry::PluginModuleDead(PluginModule* dead_module) { | 78 void PepperPluginRegistry::PluginModuleDead(PluginModule* dead_module) { |
| 79 // DANGER: Don't dereference the dead_module pointer! It may be in the | 79 // DANGER: Don't dereference the dead_module pointer! It may be in the |
| 80 // process of being deleted. | 80 // process of being deleted. |
| 81 | 81 |
| 82 // Modules aren't destroyed very often and there are normally at most a | 82 // Modules aren't destroyed very often and there are normally at most a |
| 83 // couple of them. So for now we just do a brute-force search. | 83 // couple of them. So for now we just do a brute-force search. |
| 84 for (NonOwningModuleMap::iterator i = live_modules_.begin(); | 84 for (NonOwningModuleMap::iterator i = live_modules_.begin(); |
| 85 i != live_modules_.end(); ++i) { | 85 i != live_modules_.end(); |
| 86 ++i) { |
| 86 if (i->second == dead_module) { | 87 if (i->second == dead_module) { |
| 87 live_modules_.erase(i); | 88 live_modules_.erase(i); |
| 88 return; | 89 return; |
| 89 } | 90 } |
| 90 } | 91 } |
| 91 // Can occur in tests. | 92 // Can occur in tests. |
| 92 } | 93 } |
| 93 | 94 |
| 94 PepperPluginRegistry::~PepperPluginRegistry() { | 95 PepperPluginRegistry::~PepperPluginRegistry() { |
| 95 // Explicitly clear all preloaded modules first. This will cause callbacks | 96 // Explicitly clear all preloaded modules first. This will cause callbacks |
| 96 // to erase these modules from the live_modules_ list, and we don't want | 97 // to erase these modules from the live_modules_ list, and we don't want |
| 97 // that to happen implicitly out-of-order. | 98 // that to happen implicitly out-of-order. |
| 98 preloaded_modules_.clear(); | 99 preloaded_modules_.clear(); |
| 99 | 100 |
| 100 DCHECK(live_modules_.empty()); | 101 DCHECK(live_modules_.empty()); |
| 101 } | 102 } |
| 102 | 103 |
| 103 PepperPluginRegistry::PepperPluginRegistry() { | 104 PepperPluginRegistry::PepperPluginRegistry() {} |
| 104 } | |
| 105 | 105 |
| 106 void PepperPluginRegistry::Initialize() { | 106 void PepperPluginRegistry::Initialize() { |
| 107 ComputePepperPluginList(&plugin_list_); | 107 ComputePepperPluginList(&plugin_list_); |
| 108 | 108 |
| 109 // Note that in each case, AddLiveModule must be called before completing | 109 // Note that in each case, AddLiveModule must be called before completing |
| 110 // initialization. If we bail out (in the continue clauses) before saving | 110 // initialization. If we bail out (in the continue clauses) before saving |
| 111 // the initialized module, it will still try to unregister itself in its | 111 // the initialized module, it will still try to unregister itself in its |
| 112 // destructor. | 112 // destructor. |
| 113 for (size_t i = 0; i < plugin_list_.size(); i++) { | 113 for (size_t i = 0; i < plugin_list_.size(); i++) { |
| 114 const PepperPluginInfo& current = plugin_list_[i]; | 114 const PepperPluginInfo& current = plugin_list_[i]; |
| 115 if (current.is_out_of_process) | 115 if (current.is_out_of_process) |
| 116 continue; // Out of process plugins need no special pre-initialization. | 116 continue; // Out of process plugins need no special pre-initialization. |
| 117 | 117 |
| 118 scoped_refptr<PluginModule> module = new PluginModule( | 118 scoped_refptr<PluginModule> module = |
| 119 current.name, current.path, | 119 new PluginModule(current.name, |
| 120 ppapi::PpapiPermissions(current.permissions)); | 120 current.path, |
| 121 ppapi::PpapiPermissions(current.permissions)); |
| 121 AddLiveModule(current.path, module.get()); | 122 AddLiveModule(current.path, module.get()); |
| 122 if (current.is_internal) { | 123 if (current.is_internal) { |
| 123 if (!module->InitAsInternalPlugin(current.internal_entry_points)) { | 124 if (!module->InitAsInternalPlugin(current.internal_entry_points)) { |
| 124 DLOG(ERROR) << "Failed to load pepper module: " << current.path.value(); | 125 DLOG(ERROR) << "Failed to load pepper module: " << current.path.value(); |
| 125 continue; | 126 continue; |
| 126 } | 127 } |
| 127 } else { | 128 } else { |
| 128 // Preload all external plugins we're not running out of process. | 129 // Preload all external plugins we're not running out of process. |
| 129 if (!module->InitAsLibrary(current.path)) { | 130 if (!module->InitAsLibrary(current.path)) { |
| 130 DLOG(ERROR) << "Failed to load pepper module: " << current.path.value(); | 131 DLOG(ERROR) << "Failed to load pepper module: " << current.path.value(); |
| 131 continue; | 132 continue; |
| 132 } | 133 } |
| 133 } | 134 } |
| 134 preloaded_modules_[current.path] = module; | 135 preloaded_modules_[current.path] = module; |
| 135 } | 136 } |
| 136 } | 137 } |
| 137 | 138 |
| 138 } // namespace content | 139 } // namespace content |
| OLD | NEW |