| 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 "webkit/plugins/ppapi/host_globals.h" | 5 #include "webkit/plugins/ppapi/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" |
| 11 #include "base/rand_util.h" | 11 #include "base/rand_util.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "base/task_runner.h" | 13 #include "base/task_runner.h" |
| 14 #include "ppapi/shared_impl/api_id.h" | 14 #include "ppapi/shared_impl/api_id.h" |
| 15 #include "ppapi/shared_impl/id_assignment.h" | 15 #include "ppapi/shared_impl/id_assignment.h" |
| 16 #include "third_party/WebKit/public/platform/WebString.h" | 16 #include "third_party/WebKit/public/platform/WebString.h" |
| 17 #include "third_party/WebKit/public/web/WebConsoleMessage.h" | 17 #include "third_party/WebKit/public/web/WebConsoleMessage.h" |
| 18 #include "third_party/WebKit/public/web/WebDocument.h" | 18 #include "third_party/WebKit/public/web/WebDocument.h" |
| 19 #include "third_party/WebKit/public/web/WebElement.h" | 19 #include "third_party/WebKit/public/web/WebElement.h" |
| 20 #include "third_party/WebKit/public/web/WebFrame.h" | 20 #include "third_party/WebKit/public/web/WebFrame.h" |
| 21 #include "third_party/WebKit/public/web/WebPluginContainer.h" | 21 #include "third_party/WebKit/public/web/WebPluginContainer.h" |
| 22 #include "webkit/plugins/plugin_switches.h" | 22 #include "webkit/plugins/plugin_switches.h" |
| 23 #include "webkit/plugins/ppapi/plugin_module.h" | 23 #include "webkit/plugins/ppapi/plugin_module.h" |
| 24 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" | 24 #include "webkit/plugins/ppapi/ppapi_plugin_instance_impl.h" |
| 25 | 25 |
| 26 using ppapi::CheckIdType; | 26 using ppapi::CheckIdType; |
| 27 using ppapi::MakeTypedId; | 27 using ppapi::MakeTypedId; |
| 28 using ppapi::PPIdType; | 28 using ppapi::PPIdType; |
| 29 using ppapi::ResourceTracker; | 29 using ppapi::ResourceTracker; |
| 30 using WebKit::WebConsoleMessage; | 30 using WebKit::WebConsoleMessage; |
| 31 using WebKit::WebString; | 31 using WebKit::WebString; |
| 32 | 32 |
| 33 namespace webkit { | 33 namespace webkit { |
| 34 namespace ppapi { | 34 namespace ppapi { |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 } | 112 } |
| 113 | 113 |
| 114 ::ppapi::thunk::PPB_Instance_API* HostGlobals::GetInstanceAPI( | 114 ::ppapi::thunk::PPB_Instance_API* HostGlobals::GetInstanceAPI( |
| 115 PP_Instance instance) { | 115 PP_Instance instance) { |
| 116 // The InstanceAPI is just implemented by the PluginInstance object. | 116 // The InstanceAPI is just implemented by the PluginInstance object. |
| 117 return GetInstance(instance); | 117 return GetInstance(instance); |
| 118 } | 118 } |
| 119 | 119 |
| 120 ::ppapi::thunk::ResourceCreationAPI* HostGlobals::GetResourceCreationAPI( | 120 ::ppapi::thunk::ResourceCreationAPI* HostGlobals::GetResourceCreationAPI( |
| 121 PP_Instance pp_instance) { | 121 PP_Instance pp_instance) { |
| 122 PluginInstance* instance = GetInstance(pp_instance); | 122 PluginInstanceImpl* instance = GetInstance(pp_instance); |
| 123 if (!instance) | 123 if (!instance) |
| 124 return NULL; | 124 return NULL; |
| 125 return &instance->resource_creation(); | 125 return &instance->resource_creation(); |
| 126 } | 126 } |
| 127 | 127 |
| 128 PP_Module HostGlobals::GetModuleForInstance(PP_Instance instance) { | 128 PP_Module HostGlobals::GetModuleForInstance(PP_Instance instance) { |
| 129 PluginInstance* inst = GetInstance(instance); | 129 PluginInstanceImpl* inst = GetInstance(instance); |
| 130 if (!inst) | 130 if (!inst) |
| 131 return 0; | 131 return 0; |
| 132 return inst->module()->pp_module(); | 132 return inst->module()->pp_module(); |
| 133 } | 133 } |
| 134 | 134 |
| 135 std::string HostGlobals::GetCmdLine() { | 135 std::string HostGlobals::GetCmdLine() { |
| 136 return CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 136 return CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 137 switches::kPpapiFlashArgs); | 137 switches::kPpapiFlashArgs); |
| 138 } | 138 } |
| 139 | 139 |
| 140 void HostGlobals::PreCacheFontForFlash(const void* logfontw) { | 140 void HostGlobals::PreCacheFontForFlash(const void* logfontw) { |
| 141 // Not implemented in-process. | 141 // Not implemented in-process. |
| 142 } | 142 } |
| 143 | 143 |
| 144 base::Lock* HostGlobals::GetProxyLock() { | 144 base::Lock* HostGlobals::GetProxyLock() { |
| 145 // We do not lock on the host side. | 145 // We do not lock on the host side. |
| 146 return NULL; | 146 return NULL; |
| 147 } | 147 } |
| 148 | 148 |
| 149 void HostGlobals::LogWithSource(PP_Instance instance, | 149 void HostGlobals::LogWithSource(PP_Instance instance, |
| 150 PP_LogLevel level, | 150 PP_LogLevel level, |
| 151 const std::string& source, | 151 const std::string& source, |
| 152 const std::string& value) { | 152 const std::string& value) { |
| 153 PluginInstance* instance_object = HostGlobals::Get()->GetInstance(instance); | 153 PluginInstanceImpl* instance_object = |
| 154 HostGlobals::Get()->GetInstance(instance); |
| 154 if (instance_object) { | 155 if (instance_object) { |
| 155 instance_object->container()->element().document().frame()-> | 156 instance_object->container()->element().document().frame()-> |
| 156 addMessageToConsole(MakeLogMessage(level, source, value)); | 157 addMessageToConsole(MakeLogMessage(level, source, value)); |
| 157 } else { | 158 } else { |
| 158 BroadcastLogWithSource(0, level, source, value); | 159 BroadcastLogWithSource(0, level, source, value); |
| 159 } | 160 } |
| 160 } | 161 } |
| 161 | 162 |
| 162 void HostGlobals::BroadcastLogWithSource(PP_Module pp_module, | 163 void HostGlobals::BroadcastLogWithSource(PP_Module pp_module, |
| 163 PP_LogLevel level, | 164 PP_LogLevel level, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 178 } | 179 } |
| 179 } | 180 } |
| 180 | 181 |
| 181 WebConsoleMessage message = MakeLogMessage(level, source, value); | 182 WebConsoleMessage message = MakeLogMessage(level, source, value); |
| 182 for (ContainerSet::iterator i = containers.begin(); | 183 for (ContainerSet::iterator i = containers.begin(); |
| 183 i != containers.end(); ++i) | 184 i != containers.end(); ++i) |
| 184 (*i)->element().document().frame()->addMessageToConsole(message); | 185 (*i)->element().document().frame()->addMessageToConsole(message); |
| 185 } | 186 } |
| 186 | 187 |
| 187 base::TaskRunner* HostGlobals::GetFileTaskRunner(PP_Instance instance) { | 188 base::TaskRunner* HostGlobals::GetFileTaskRunner(PP_Instance instance) { |
| 188 scoped_refptr<PluginInstance> plugin_instance = GetInstance(instance); | 189 scoped_refptr<PluginInstanceImpl> plugin_instance = GetInstance(instance); |
| 189 DCHECK(plugin_instance.get()); | 190 DCHECK(plugin_instance.get()); |
| 190 scoped_refptr<base::MessageLoopProxy> message_loop = | 191 scoped_refptr<base::MessageLoopProxy> message_loop = |
| 191 plugin_instance->delegate()->GetFileThreadMessageLoopProxy(); | 192 plugin_instance->delegate()->GetFileThreadMessageLoopProxy(); |
| 192 return message_loop.get(); | 193 return message_loop.get(); |
| 193 } | 194 } |
| 194 | 195 |
| 195 ::ppapi::MessageLoopShared* HostGlobals::GetCurrentMessageLoop() { | 196 ::ppapi::MessageLoopShared* HostGlobals::GetCurrentMessageLoop() { |
| 196 return NULL; | 197 return NULL; |
| 197 } | 198 } |
| 198 | 199 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 228 | 229 |
| 229 PluginModule* HostGlobals::GetModule(PP_Module module) { | 230 PluginModule* HostGlobals::GetModule(PP_Module module) { |
| 230 DLOG_IF(ERROR, !CheckIdType(module, ::ppapi::PP_ID_TYPE_MODULE)) | 231 DLOG_IF(ERROR, !CheckIdType(module, ::ppapi::PP_ID_TYPE_MODULE)) |
| 231 << module << " is not a PP_Module."; | 232 << module << " is not a PP_Module."; |
| 232 ModuleMap::iterator found = module_map_.find(module); | 233 ModuleMap::iterator found = module_map_.find(module); |
| 233 if (found == module_map_.end()) | 234 if (found == module_map_.end()) |
| 234 return NULL; | 235 return NULL; |
| 235 return found->second; | 236 return found->second; |
| 236 } | 237 } |
| 237 | 238 |
| 238 PP_Instance HostGlobals::AddInstance(PluginInstance* instance) { | 239 PP_Instance HostGlobals::AddInstance(PluginInstanceImpl* instance) { |
| 239 DCHECK(instance_map_.find(instance->pp_instance()) == instance_map_.end()); | 240 DCHECK(instance_map_.find(instance->pp_instance()) == instance_map_.end()); |
| 240 | 241 |
| 241 // Use a random number for the instance ID. This helps prevent some | 242 // Use a random number for the instance ID. This helps prevent some |
| 242 // accidents. See also AddModule below. | 243 // accidents. See also AddModule below. |
| 243 // | 244 // |
| 244 // Need to make sure the random number isn't a duplicate or 0. | 245 // Need to make sure the random number isn't a duplicate or 0. |
| 245 PP_Instance new_instance; | 246 PP_Instance new_instance; |
| 246 do { | 247 do { |
| 247 new_instance = MakeTypedId(static_cast<PP_Instance>(base::RandUint64()), | 248 new_instance = MakeTypedId(static_cast<PP_Instance>(base::RandUint64()), |
| 248 ::ppapi::PP_ID_TYPE_INSTANCE); | 249 ::ppapi::PP_ID_TYPE_INSTANCE); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 260 resource_tracker_.DidDeleteInstance(instance); | 261 resource_tracker_.DidDeleteInstance(instance); |
| 261 host_var_tracker_.DidDeleteInstance(instance); | 262 host_var_tracker_.DidDeleteInstance(instance); |
| 262 instance_map_.erase(instance); | 263 instance_map_.erase(instance); |
| 263 } | 264 } |
| 264 | 265 |
| 265 void HostGlobals::InstanceCrashed(PP_Instance instance) { | 266 void HostGlobals::InstanceCrashed(PP_Instance instance) { |
| 266 resource_tracker_.DidDeleteInstance(instance); | 267 resource_tracker_.DidDeleteInstance(instance); |
| 267 host_var_tracker_.DidDeleteInstance(instance); | 268 host_var_tracker_.DidDeleteInstance(instance); |
| 268 } | 269 } |
| 269 | 270 |
| 270 PluginInstance* HostGlobals::GetInstance(PP_Instance instance) { | 271 PluginInstanceImpl* HostGlobals::GetInstance(PP_Instance instance) { |
| 271 DLOG_IF(ERROR, !CheckIdType(instance, ::ppapi::PP_ID_TYPE_INSTANCE)) | 272 DLOG_IF(ERROR, !CheckIdType(instance, ::ppapi::PP_ID_TYPE_INSTANCE)) |
| 272 << instance << " is not a PP_Instance."; | 273 << instance << " is not a PP_Instance."; |
| 273 InstanceMap::iterator found = instance_map_.find(instance); | 274 InstanceMap::iterator found = instance_map_.find(instance); |
| 274 if (found == instance_map_.end()) | 275 if (found == instance_map_.end()) |
| 275 return NULL; | 276 return NULL; |
| 276 return found->second; | 277 return found->second; |
| 277 } | 278 } |
| 278 | 279 |
| 279 bool HostGlobals::IsHostGlobals() const { | 280 bool HostGlobals::IsHostGlobals() const { |
| 280 return true; | 281 return true; |
| 281 } | 282 } |
| 282 | 283 |
| 283 } // namespace ppapi | 284 } // namespace ppapi |
| 284 } // namespace webkit | 285 } // namespace webkit |
| OLD | NEW |