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/plugin_module.h" | 10 #include "content/renderer/pepper/plugin_module.h" |
10 #include "ppapi/shared_impl/ppapi_permissions.h" | 11 #include "ppapi/shared_impl/ppapi_permissions.h" |
11 | 12 |
12 namespace content { | 13 namespace content { |
13 | 14 |
14 // static | 15 // static |
15 PepperPluginRegistry* PepperPluginRegistry::GetInstance() { | 16 PepperPluginRegistry* PepperPluginRegistry::GetInstance() { |
16 static PepperPluginRegistry* registry = NULL; | 17 static PepperPluginRegistry* registry = NULL; |
17 // This object leaks. It is a temporary hack to work around a crash. | 18 // This object leaks. It is a temporary hack to work around a crash. |
18 // http://code.google.com/p/chromium/issues/detail?id=63234 | 19 // http://code.google.com/p/chromium/issues/detail?id=63234 |
(...skipping 17 matching lines...) Expand all Loading... |
36 // PluginService. | 37 // PluginService. |
37 PepperPluginInfo plugin; | 38 PepperPluginInfo plugin; |
38 if (!MakePepperPluginInfo(info, &plugin)) | 39 if (!MakePepperPluginInfo(info, &plugin)) |
39 return NULL; | 40 return NULL; |
40 | 41 |
41 plugin_list_.push_back(plugin); | 42 plugin_list_.push_back(plugin); |
42 return &plugin_list_[plugin_list_.size() - 1]; | 43 return &plugin_list_[plugin_list_.size() - 1]; |
43 } | 44 } |
44 | 45 |
45 PluginModule* PepperPluginRegistry::GetLiveModule(const base::FilePath& path) { | 46 PluginModule* PepperPluginRegistry::GetLiveModule(const base::FilePath& path) { |
46 NonOwningModuleMap::iterator it = live_modules_.find(path); | 47 NonOwningModuleMap::iterator module_iter = live_modules_.find(path); |
47 if (it == live_modules_.end()) | 48 if (module_iter == live_modules_.end()) |
48 return NULL; | 49 return NULL; |
49 return it->second; | 50 |
| 51 // Check the instances for the module to see if they've all been Delete()d. |
| 52 // We don't want to return a PluginModule in that case, since the plugin may |
| 53 // have exited already. |
| 54 const PluginModule::PluginInstanceSet& instance_set = |
| 55 module_iter->second->GetAllInstances(); |
| 56 |
| 57 // If instance_set is empty, InstanceCreated() hasn't been called yet, so |
| 58 // it's safe to return the PluginModule. |
| 59 if (instance_set.empty()) |
| 60 return module_iter->second; |
| 61 |
| 62 PluginModule::PluginInstanceSet::const_iterator instance_iter = |
| 63 instance_set.begin(); |
| 64 while (instance_iter != instance_set.end()) { |
| 65 if (!(*instance_iter)->is_deleted()) |
| 66 return module_iter->second; |
| 67 ++instance_iter; |
| 68 } |
| 69 return NULL; |
50 } | 70 } |
51 | 71 |
52 void PepperPluginRegistry::AddLiveModule(const base::FilePath& path, | 72 void PepperPluginRegistry::AddLiveModule(const base::FilePath& path, |
53 PluginModule* module) { | 73 PluginModule* module) { |
54 DCHECK(live_modules_.find(path) == live_modules_.end()); | 74 DCHECK(live_modules_.find(path) == live_modules_.end()); |
55 live_modules_[path] = module; | 75 live_modules_[path] = module; |
56 } | 76 } |
57 | 77 |
58 void PepperPluginRegistry::PluginModuleDead(PluginModule* dead_module) { | 78 void PepperPluginRegistry::PluginModuleDead(PluginModule* dead_module) { |
59 // 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 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 if (!module->InitAsLibrary(current.path)) { | 129 if (!module->InitAsLibrary(current.path)) { |
110 DLOG(ERROR) << "Failed to load pepper module: " << current.path.value(); | 130 DLOG(ERROR) << "Failed to load pepper module: " << current.path.value(); |
111 continue; | 131 continue; |
112 } | 132 } |
113 } | 133 } |
114 preloaded_modules_[current.path] = module; | 134 preloaded_modules_[current.path] = module; |
115 } | 135 } |
116 } | 136 } |
117 | 137 |
118 } // namespace content | 138 } // namespace content |
OLD | NEW |