| 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 21 matching lines...) Expand all Loading... |
| 32 using blink::WebConsoleMessage; | 32 using blink::WebConsoleMessage; |
| 33 using blink::WebString; | 33 using blink::WebString; |
| 34 | 34 |
| 35 namespace content { | 35 namespace content { |
| 36 | 36 |
| 37 namespace { | 37 namespace { |
| 38 | 38 |
| 39 typedef std::set<blink::WebPluginContainer*> ContainerSet; | 39 typedef std::set<blink::WebPluginContainer*> ContainerSet; |
| 40 | 40 |
| 41 // Adds all WebPluginContainers associated with the given module to the set. | 41 // Adds all WebPluginContainers associated with the given module to the set. |
| 42 void GetAllContainersForModule(PluginModule* module, | 42 void GetAllContainersForModule(PluginModule* module, ContainerSet* containers) { |
| 43 ContainerSet* containers) { | 43 const PluginModule::PluginInstanceSet& instances = module->GetAllInstances(); |
| 44 const PluginModule::PluginInstanceSet& instances = | |
| 45 module->GetAllInstances(); | |
| 46 for (PluginModule::PluginInstanceSet::const_iterator i = instances.begin(); | 44 for (PluginModule::PluginInstanceSet::const_iterator i = instances.begin(); |
| 47 i != instances.end(); ++i) | 45 i != instances.end(); |
| 46 ++i) |
| 48 containers->insert((*i)->container()); | 47 containers->insert((*i)->container()); |
| 49 } | 48 } |
| 50 | 49 |
| 51 WebConsoleMessage::Level LogLevelToWebLogLevel(PP_LogLevel level) { | 50 WebConsoleMessage::Level LogLevelToWebLogLevel(PP_LogLevel level) { |
| 52 switch (level) { | 51 switch (level) { |
| 53 case PP_LOGLEVEL_TIP: | 52 case PP_LOGLEVEL_TIP: |
| 54 return WebConsoleMessage::LevelDebug; | 53 return WebConsoleMessage::LevelDebug; |
| 55 case PP_LOGLEVEL_LOG: | 54 case PP_LOGLEVEL_LOG: |
| 56 return WebConsoleMessage::LevelLog; | 55 return WebConsoleMessage::LevelLog; |
| 57 case PP_LOGLEVEL_WARNING: | 56 case PP_LOGLEVEL_WARNING: |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 | 88 |
| 90 HostGlobals::~HostGlobals() { | 89 HostGlobals::~HostGlobals() { |
| 91 DCHECK(host_globals_ == this || !host_globals_); | 90 DCHECK(host_globals_ == this || !host_globals_); |
| 92 host_globals_ = NULL; | 91 host_globals_ = NULL; |
| 93 } | 92 } |
| 94 | 93 |
| 95 ppapi::ResourceTracker* HostGlobals::GetResourceTracker() { | 94 ppapi::ResourceTracker* HostGlobals::GetResourceTracker() { |
| 96 return &resource_tracker_; | 95 return &resource_tracker_; |
| 97 } | 96 } |
| 98 | 97 |
| 99 ppapi::VarTracker* HostGlobals::GetVarTracker() { | 98 ppapi::VarTracker* HostGlobals::GetVarTracker() { return &host_var_tracker_; } |
| 100 return &host_var_tracker_; | |
| 101 } | |
| 102 | 99 |
| 103 ppapi::CallbackTracker* HostGlobals::GetCallbackTrackerForInstance( | 100 ppapi::CallbackTracker* HostGlobals::GetCallbackTrackerForInstance( |
| 104 PP_Instance instance) { | 101 PP_Instance instance) { |
| 105 InstanceMap::iterator found = instance_map_.find(instance); | 102 InstanceMap::iterator found = instance_map_.find(instance); |
| 106 if (found == instance_map_.end()) | 103 if (found == instance_map_.end()) |
| 107 return NULL; | 104 return NULL; |
| 108 return found->second->module()->GetCallbackTracker().get(); | 105 return found->second->module()->GetCallbackTracker().get(); |
| 109 } | 106 } |
| 110 | 107 |
| 111 ppapi::thunk::PPB_Instance_API* HostGlobals::GetInstanceAPI( | 108 ppapi::thunk::PPB_Instance_API* HostGlobals::GetInstanceAPI( |
| (...skipping 26 matching lines...) Expand all Loading... |
| 138 // Not implemented in-process. | 135 // Not implemented in-process. |
| 139 } | 136 } |
| 140 | 137 |
| 141 void HostGlobals::LogWithSource(PP_Instance instance, | 138 void HostGlobals::LogWithSource(PP_Instance instance, |
| 142 PP_LogLevel level, | 139 PP_LogLevel level, |
| 143 const std::string& source, | 140 const std::string& source, |
| 144 const std::string& value) { | 141 const std::string& value) { |
| 145 PepperPluginInstanceImpl* instance_object = | 142 PepperPluginInstanceImpl* instance_object = |
| 146 HostGlobals::Get()->GetInstance(instance); | 143 HostGlobals::Get()->GetInstance(instance); |
| 147 if (instance_object) { | 144 if (instance_object) { |
| 148 instance_object->container()->element().document().frame()-> | 145 instance_object->container() |
| 149 addMessageToConsole(MakeLogMessage(level, source, value)); | 146 ->element() |
| 147 .document() |
| 148 .frame() |
| 149 ->addMessageToConsole(MakeLogMessage(level, source, value)); |
| 150 } else { | 150 } else { |
| 151 BroadcastLogWithSource(0, level, source, value); | 151 BroadcastLogWithSource(0, level, source, value); |
| 152 } | 152 } |
| 153 } | 153 } |
| 154 | 154 |
| 155 void HostGlobals::BroadcastLogWithSource(PP_Module pp_module, | 155 void HostGlobals::BroadcastLogWithSource(PP_Module pp_module, |
| 156 PP_LogLevel level, | 156 PP_LogLevel level, |
| 157 const std::string& source, | 157 const std::string& source, |
| 158 const std::string& value) { | 158 const std::string& value) { |
| 159 // Get the unique containers associated with the broadcast. This prevents us | 159 // Get the unique containers associated with the broadcast. This prevents us |
| 160 // from sending the same message to the same console when there are two | 160 // from sending the same message to the same console when there are two |
| 161 // instances on the page. | 161 // instances on the page. |
| 162 ContainerSet containers; | 162 ContainerSet containers; |
| 163 PluginModule* module = GetModule(pp_module); | 163 PluginModule* module = GetModule(pp_module); |
| 164 if (module) { | 164 if (module) { |
| 165 GetAllContainersForModule(module, &containers); | 165 GetAllContainersForModule(module, &containers); |
| 166 } else { | 166 } else { |
| 167 // Unknown module, get containers for all modules. | 167 // Unknown module, get containers for all modules. |
| 168 for (ModuleMap::const_iterator i = module_map_.begin(); | 168 for (ModuleMap::const_iterator i = module_map_.begin(); |
| 169 i != module_map_.end(); ++i) { | 169 i != module_map_.end(); |
| 170 ++i) { |
| 170 GetAllContainersForModule(i->second, &containers); | 171 GetAllContainersForModule(i->second, &containers); |
| 171 } | 172 } |
| 172 } | 173 } |
| 173 | 174 |
| 174 WebConsoleMessage message = MakeLogMessage(level, source, value); | 175 WebConsoleMessage message = MakeLogMessage(level, source, value); |
| 175 for (ContainerSet::iterator i = containers.begin(); | 176 for (ContainerSet::iterator i = containers.begin(); i != containers.end(); |
| 176 i != containers.end(); ++i) | 177 ++i) |
| 177 (*i)->element().document().frame()->addMessageToConsole(message); | 178 (*i)->element().document().frame()->addMessageToConsole(message); |
| 178 } | 179 } |
| 179 | 180 |
| 180 base::TaskRunner* HostGlobals::GetFileTaskRunner() { | 181 base::TaskRunner* HostGlobals::GetFileTaskRunner() { |
| 181 return RenderThreadImpl::current()->GetFileThreadMessageLoopProxy().get(); | 182 return RenderThreadImpl::current()->GetFileThreadMessageLoopProxy().get(); |
| 182 } | 183 } |
| 183 | 184 |
| 184 ppapi::MessageLoopShared* HostGlobals::GetCurrentMessageLoop() { | 185 ppapi::MessageLoopShared* HostGlobals::GetCurrentMessageLoop() { return NULL; } |
| 185 return NULL; | |
| 186 } | |
| 187 | 186 |
| 188 PP_Module HostGlobals::AddModule(PluginModule* module) { | 187 PP_Module HostGlobals::AddModule(PluginModule* module) { |
| 189 #ifndef NDEBUG | 188 #ifndef NDEBUG |
| 190 // Make sure we're not adding one more than once. | 189 // Make sure we're not adding one more than once. |
| 191 for (ModuleMap::const_iterator i = module_map_.begin(); | 190 for (ModuleMap::const_iterator i = module_map_.begin(); |
| 192 i != module_map_.end(); ++i) | 191 i != module_map_.end(); |
| 192 ++i) |
| 193 DCHECK(i->second != module); | 193 DCHECK(i->second != module); |
| 194 #endif | 194 #endif |
| 195 | 195 |
| 196 // See AddInstance. | 196 // See AddInstance. |
| 197 PP_Module new_module; | 197 PP_Module new_module; |
| 198 do { | 198 do { |
| 199 new_module = MakeTypedId(static_cast<PP_Module>(base::RandUint64()), | 199 new_module = MakeTypedId(static_cast<PP_Module>(base::RandUint64()), |
| 200 ppapi::PP_ID_TYPE_MODULE); | 200 ppapi::PP_ID_TYPE_MODULE); |
| 201 } while (!new_module || | 201 } while (!new_module || module_map_.find(new_module) != module_map_.end()); |
| 202 module_map_.find(new_module) != module_map_.end()); | |
| 203 module_map_[new_module] = module; | 202 module_map_[new_module] = module; |
| 204 return new_module; | 203 return new_module; |
| 205 } | 204 } |
| 206 | 205 |
| 207 void HostGlobals::ModuleDeleted(PP_Module module) { | 206 void HostGlobals::ModuleDeleted(PP_Module module) { |
| 208 DLOG_IF(ERROR, !CheckIdType(module, ppapi::PP_ID_TYPE_MODULE)) | 207 DLOG_IF(ERROR, !CheckIdType(module, ppapi::PP_ID_TYPE_MODULE)) |
| 209 << module << " is not a PP_Module."; | 208 << module << " is not a PP_Module."; |
| 210 ModuleMap::iterator found = module_map_.find(module); | 209 ModuleMap::iterator found = module_map_.find(module); |
| 211 if (found == module_map_.end()) { | 210 if (found == module_map_.end()) { |
| 212 NOTREACHED(); | 211 NOTREACHED(); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 | 257 |
| 259 PepperPluginInstanceImpl* HostGlobals::GetInstance(PP_Instance instance) { | 258 PepperPluginInstanceImpl* HostGlobals::GetInstance(PP_Instance instance) { |
| 260 DLOG_IF(ERROR, !CheckIdType(instance, ppapi::PP_ID_TYPE_INSTANCE)) | 259 DLOG_IF(ERROR, !CheckIdType(instance, ppapi::PP_ID_TYPE_INSTANCE)) |
| 261 << instance << " is not a PP_Instance."; | 260 << instance << " is not a PP_Instance."; |
| 262 InstanceMap::iterator found = instance_map_.find(instance); | 261 InstanceMap::iterator found = instance_map_.find(instance); |
| 263 if (found == instance_map_.end()) | 262 if (found == instance_map_.end()) |
| 264 return NULL; | 263 return NULL; |
| 265 return found->second; | 264 return found->second; |
| 266 } | 265 } |
| 267 | 266 |
| 268 bool HostGlobals::IsHostGlobals() const { | 267 bool HostGlobals::IsHostGlobals() const { return true; } |
| 269 return true; | |
| 270 } | |
| 271 | 268 |
| 272 } // namespace content | 269 } // namespace content |
| OLD | NEW |