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/host_globals.h" | 5 #include "content/renderer/pepper/host_globals.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 23 matching lines...) Expand all Loading... |
34 using blink::WebPluginContainer; | 34 using blink::WebPluginContainer; |
35 using blink::WebString; | 35 using blink::WebString; |
36 | 36 |
37 namespace content { | 37 namespace content { |
38 | 38 |
39 namespace { | 39 namespace { |
40 | 40 |
41 typedef std::set<WebPluginContainer*> ContainerSet; | 41 typedef std::set<WebPluginContainer*> ContainerSet; |
42 | 42 |
43 // Adds all WebPluginContainers associated with the given module to the set. | 43 // Adds all WebPluginContainers associated with the given module to the set. |
44 void GetAllContainersForModule(PluginModule* module, | 44 void GetAllContainersForModule(PluginModule* module, ContainerSet* containers) { |
45 ContainerSet* containers) { | 45 const PluginModule::PluginInstanceSet& instances = module->GetAllInstances(); |
46 const PluginModule::PluginInstanceSet& instances = | |
47 module->GetAllInstances(); | |
48 for (PluginModule::PluginInstanceSet::const_iterator i = instances.begin(); | 46 for (PluginModule::PluginInstanceSet::const_iterator i = instances.begin(); |
49 i != instances.end(); ++i) { | 47 i != instances.end(); |
| 48 ++i) { |
50 WebPluginContainer* container = (*i)->container(); | 49 WebPluginContainer* container = (*i)->container(); |
51 // If "Delete" is called on an instance, the instance sets its container to | 50 // If "Delete" is called on an instance, the instance sets its container to |
52 // NULL, but the instance may actually outlive its container. Callers of | 51 // NULL, but the instance may actually outlive its container. Callers of |
53 // GetAllContainersForModule only want to know about valid containers. | 52 // GetAllContainersForModule only want to know about valid containers. |
54 if (container) | 53 if (container) |
55 containers->insert(container); | 54 containers->insert(container); |
56 } | 55 } |
57 } | 56 } |
58 | 57 |
59 WebConsoleMessage::Level LogLevelToWebLogLevel(PP_LogLevel level) { | 58 WebConsoleMessage::Level LogLevelToWebLogLevel(PP_LogLevel level) { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 | 96 |
98 HostGlobals::~HostGlobals() { | 97 HostGlobals::~HostGlobals() { |
99 DCHECK(host_globals_ == this || !host_globals_); | 98 DCHECK(host_globals_ == this || !host_globals_); |
100 host_globals_ = NULL; | 99 host_globals_ = NULL; |
101 } | 100 } |
102 | 101 |
103 ppapi::ResourceTracker* HostGlobals::GetResourceTracker() { | 102 ppapi::ResourceTracker* HostGlobals::GetResourceTracker() { |
104 return &resource_tracker_; | 103 return &resource_tracker_; |
105 } | 104 } |
106 | 105 |
107 ppapi::VarTracker* HostGlobals::GetVarTracker() { | 106 ppapi::VarTracker* HostGlobals::GetVarTracker() { return &host_var_tracker_; } |
108 return &host_var_tracker_; | |
109 } | |
110 | 107 |
111 ppapi::CallbackTracker* HostGlobals::GetCallbackTrackerForInstance( | 108 ppapi::CallbackTracker* HostGlobals::GetCallbackTrackerForInstance( |
112 PP_Instance instance) { | 109 PP_Instance instance) { |
113 InstanceMap::iterator found = instance_map_.find(instance); | 110 InstanceMap::iterator found = instance_map_.find(instance); |
114 if (found == instance_map_.end()) | 111 if (found == instance_map_.end()) |
115 return NULL; | 112 return NULL; |
116 return found->second->module()->GetCallbackTracker().get(); | 113 return found->second->module()->GetCallbackTracker().get(); |
117 } | 114 } |
118 | 115 |
119 ppapi::thunk::PPB_Instance_API* HostGlobals::GetInstanceAPI( | 116 ppapi::thunk::PPB_Instance_API* HostGlobals::GetInstanceAPI( |
(...skipping 26 matching lines...) Expand all Loading... |
146 // Not implemented in-process. | 143 // Not implemented in-process. |
147 } | 144 } |
148 | 145 |
149 void HostGlobals::LogWithSource(PP_Instance instance, | 146 void HostGlobals::LogWithSource(PP_Instance instance, |
150 PP_LogLevel level, | 147 PP_LogLevel level, |
151 const std::string& source, | 148 const std::string& source, |
152 const std::string& value) { | 149 const std::string& value) { |
153 PepperPluginInstanceImpl* instance_object = | 150 PepperPluginInstanceImpl* instance_object = |
154 HostGlobals::Get()->GetInstance(instance); | 151 HostGlobals::Get()->GetInstance(instance); |
155 if (instance_object) { | 152 if (instance_object) { |
156 instance_object->container()->element().document().frame()-> | 153 instance_object->container() |
157 addMessageToConsole(MakeLogMessage(level, source, value)); | 154 ->element() |
| 155 .document() |
| 156 .frame() |
| 157 ->addMessageToConsole(MakeLogMessage(level, source, value)); |
158 } else { | 158 } else { |
159 BroadcastLogWithSource(0, level, source, value); | 159 BroadcastLogWithSource(0, level, source, value); |
160 } | 160 } |
161 } | 161 } |
162 | 162 |
163 void HostGlobals::BroadcastLogWithSource(PP_Module pp_module, | 163 void HostGlobals::BroadcastLogWithSource(PP_Module pp_module, |
164 PP_LogLevel level, | 164 PP_LogLevel level, |
165 const std::string& source, | 165 const std::string& source, |
166 const std::string& value) { | 166 const std::string& value) { |
167 // Get the unique containers associated with the broadcast. This prevents us | 167 // Get the unique containers associated with the broadcast. This prevents us |
168 // from sending the same message to the same console when there are two | 168 // from sending the same message to the same console when there are two |
169 // instances on the page. | 169 // instances on the page. |
170 ContainerSet containers; | 170 ContainerSet containers; |
171 PluginModule* module = GetModule(pp_module); | 171 PluginModule* module = GetModule(pp_module); |
172 if (module) { | 172 if (module) { |
173 GetAllContainersForModule(module, &containers); | 173 GetAllContainersForModule(module, &containers); |
174 } else { | 174 } else { |
175 // Unknown module, get containers for all modules. | 175 // Unknown module, get containers for all modules. |
176 for (ModuleMap::const_iterator i = module_map_.begin(); | 176 for (ModuleMap::const_iterator i = module_map_.begin(); |
177 i != module_map_.end(); ++i) { | 177 i != module_map_.end(); |
| 178 ++i) { |
178 GetAllContainersForModule(i->second, &containers); | 179 GetAllContainersForModule(i->second, &containers); |
179 } | 180 } |
180 } | 181 } |
181 | 182 |
182 WebConsoleMessage message = MakeLogMessage(level, source, value); | 183 WebConsoleMessage message = MakeLogMessage(level, source, value); |
183 for (ContainerSet::iterator i = containers.begin(); | 184 for (ContainerSet::iterator i = containers.begin(); i != containers.end(); |
184 i != containers.end(); ++i) { | 185 ++i) { |
185 WebLocalFrame* frame = (*i)->element().document().frame(); | 186 WebLocalFrame* frame = (*i)->element().document().frame(); |
186 if (frame) | 187 if (frame) |
187 frame->addMessageToConsole(message); | 188 frame->addMessageToConsole(message); |
188 } | 189 } |
189 } | 190 } |
190 | 191 |
191 base::TaskRunner* HostGlobals::GetFileTaskRunner() { | 192 base::TaskRunner* HostGlobals::GetFileTaskRunner() { |
192 return RenderThreadImpl::current()->GetFileThreadMessageLoopProxy().get(); | 193 return RenderThreadImpl::current()->GetFileThreadMessageLoopProxy().get(); |
193 } | 194 } |
194 | 195 |
195 ppapi::MessageLoopShared* HostGlobals::GetCurrentMessageLoop() { | 196 ppapi::MessageLoopShared* HostGlobals::GetCurrentMessageLoop() { return NULL; } |
196 return NULL; | |
197 } | |
198 | 197 |
199 PP_Module HostGlobals::AddModule(PluginModule* module) { | 198 PP_Module HostGlobals::AddModule(PluginModule* module) { |
200 #ifndef NDEBUG | 199 #ifndef NDEBUG |
201 // Make sure we're not adding one more than once. | 200 // Make sure we're not adding one more than once. |
202 for (ModuleMap::const_iterator i = module_map_.begin(); | 201 for (ModuleMap::const_iterator i = module_map_.begin(); |
203 i != module_map_.end(); ++i) | 202 i != module_map_.end(); |
| 203 ++i) |
204 DCHECK(i->second != module); | 204 DCHECK(i->second != module); |
205 #endif | 205 #endif |
206 | 206 |
207 // See AddInstance. | 207 // See AddInstance. |
208 PP_Module new_module; | 208 PP_Module new_module; |
209 do { | 209 do { |
210 new_module = MakeTypedId(static_cast<PP_Module>(base::RandUint64()), | 210 new_module = MakeTypedId(static_cast<PP_Module>(base::RandUint64()), |
211 ppapi::PP_ID_TYPE_MODULE); | 211 ppapi::PP_ID_TYPE_MODULE); |
212 } while (!new_module || | 212 } while (!new_module || module_map_.find(new_module) != module_map_.end()); |
213 module_map_.find(new_module) != module_map_.end()); | |
214 module_map_[new_module] = module; | 213 module_map_[new_module] = module; |
215 return new_module; | 214 return new_module; |
216 } | 215 } |
217 | 216 |
218 void HostGlobals::ModuleDeleted(PP_Module module) { | 217 void HostGlobals::ModuleDeleted(PP_Module module) { |
219 DLOG_IF(ERROR, !CheckIdType(module, ppapi::PP_ID_TYPE_MODULE)) | 218 DLOG_IF(ERROR, !CheckIdType(module, ppapi::PP_ID_TYPE_MODULE)) |
220 << module << " is not a PP_Module."; | 219 << module << " is not a PP_Module."; |
221 ModuleMap::iterator found = module_map_.find(module); | 220 ModuleMap::iterator found = module_map_.find(module); |
222 if (found == module_map_.end()) { | 221 if (found == module_map_.end()) { |
223 NOTREACHED(); | 222 NOTREACHED(); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 | 268 |
270 PepperPluginInstanceImpl* HostGlobals::GetInstance(PP_Instance instance) { | 269 PepperPluginInstanceImpl* HostGlobals::GetInstance(PP_Instance instance) { |
271 DLOG_IF(ERROR, !CheckIdType(instance, ppapi::PP_ID_TYPE_INSTANCE)) | 270 DLOG_IF(ERROR, !CheckIdType(instance, ppapi::PP_ID_TYPE_INSTANCE)) |
272 << instance << " is not a PP_Instance."; | 271 << instance << " is not a PP_Instance."; |
273 InstanceMap::iterator found = instance_map_.find(instance); | 272 InstanceMap::iterator found = instance_map_.find(instance); |
274 if (found == instance_map_.end()) | 273 if (found == instance_map_.end()) |
275 return NULL; | 274 return NULL; |
276 return found->second; | 275 return found->second; |
277 } | 276 } |
278 | 277 |
279 bool HostGlobals::IsHostGlobals() const { | 278 bool HostGlobals::IsHostGlobals() const { return true; } |
280 return true; | |
281 } | |
282 | 279 |
283 } // namespace content | 280 } // namespace content |
OLD | NEW |