| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/glue/plugins/webplugin_delegate_impl.h" | 5 #include "webkit/glue/plugins/webplugin_delegate_impl.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| 11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
| 12 #include "base/process_util.h" | 12 #include "base/process_util.h" |
| 13 #include "base/scoped_ptr.h" |
| 13 #include "base/stats_counters.h" | 14 #include "base/stats_counters.h" |
| 14 #include "base/string_util.h" | 15 #include "base/string_util.h" |
| 15 #include "webkit/api/public/WebInputEvent.h" | 16 #include "webkit/api/public/WebInputEvent.h" |
| 16 #include "webkit/glue/glue_util.h" | 17 #include "webkit/glue/glue_util.h" |
| 17 #include "webkit/glue/plugins/plugin_constants_win.h" | 18 #include "webkit/glue/plugins/plugin_constants_win.h" |
| 18 #include "webkit/glue/plugins/plugin_instance.h" | 19 #include "webkit/glue/plugins/plugin_instance.h" |
| 19 #include "webkit/glue/plugins/plugin_lib.h" | 20 #include "webkit/glue/plugins/plugin_lib.h" |
| 20 #include "webkit/glue/plugins/plugin_list.h" | 21 #include "webkit/glue/plugins/plugin_list.h" |
| 21 #include "webkit/glue/plugins/plugin_stream_url.h" | 22 #include "webkit/glue/plugins/plugin_stream_url.h" |
| 22 #include "webkit/glue/webkit_glue.h" | 23 #include "webkit/glue/webkit_glue.h" |
| 23 | 24 |
| 24 using webkit_glue::WebPlugin; | 25 using webkit_glue::WebPlugin; |
| 25 using webkit_glue::WebPluginDelegate; | 26 using webkit_glue::WebPluginDelegate; |
| 26 using webkit_glue::WebPluginResourceClient; | 27 using webkit_glue::WebPluginResourceClient; |
| 27 using WebKit::WebCursorInfo; | 28 using WebKit::WebCursorInfo; |
| 28 using WebKit::WebKeyboardEvent; | 29 using WebKit::WebKeyboardEvent; |
| 29 using WebKit::WebInputEvent; | 30 using WebKit::WebInputEvent; |
| 30 using WebKit::WebMouseEvent; | 31 using WebKit::WebMouseEvent; |
| 31 | 32 |
| 32 WebPluginDelegate* WebPluginDelegate::Create( | 33 WebPluginDelegateImpl* WebPluginDelegateImpl::Create( |
| 33 const FilePath& filename, | 34 const FilePath& filename, |
| 34 const std::string& mime_type, | 35 const std::string& mime_type, |
| 35 gfx::PluginWindowHandle containing_view) { | 36 gfx::PluginWindowHandle containing_view) { |
| 36 scoped_refptr<NPAPI::PluginLib> plugin_lib = | 37 scoped_refptr<NPAPI::PluginLib> plugin_lib = |
| 37 NPAPI::PluginLib::CreatePluginLib(filename); | 38 NPAPI::PluginLib::CreatePluginLib(filename); |
| 38 if (plugin_lib.get() == NULL) | 39 if (plugin_lib.get() == NULL) |
| 39 return NULL; | 40 return NULL; |
| 40 | 41 |
| 41 NPError err = plugin_lib->NP_Initialize(); | 42 NPError err = plugin_lib->NP_Initialize(); |
| 42 if (err != NPERR_NO_ERROR) | 43 if (err != NPERR_NO_ERROR) |
| 43 return NULL; | 44 return NULL; |
| 44 | 45 |
| 45 scoped_refptr<NPAPI::PluginInstance> instance = | 46 scoped_refptr<NPAPI::PluginInstance> instance = |
| 46 plugin_lib->CreateInstance(mime_type); | 47 plugin_lib->CreateInstance(mime_type); |
| 47 return new WebPluginDelegateImpl(containing_view, instance.get()); | 48 return new WebPluginDelegateImpl(containing_view, instance.get()); |
| 48 } | 49 } |
| 49 | 50 |
| 50 bool WebPluginDelegateImpl::Initialize(const GURL& url, | 51 bool WebPluginDelegateImpl::Initialize( |
| 51 char** argn, | 52 const GURL& url, |
| 52 char** argv, | 53 const std::vector<std::string>& arg_names, |
| 53 int argc, | 54 const std::vector<std::string>& arg_values, |
| 54 WebPlugin* plugin, | 55 WebPlugin* plugin, |
| 55 bool load_manually) { | 56 bool load_manually) { |
| 56 plugin_ = plugin; | 57 plugin_ = plugin; |
| 57 | 58 |
| 58 instance_->set_web_plugin(plugin_); | 59 instance_->set_web_plugin(plugin_); |
| 59 NPAPI::PluginInstance* old_instance = | 60 NPAPI::PluginInstance* old_instance = |
| 60 NPAPI::PluginInstance::SetInitializingInstance(instance_); | 61 NPAPI::PluginInstance::SetInitializingInstance(instance_); |
| 61 | 62 |
| 62 if (quirks_ & PLUGIN_QUIRK_DONT_ALLOW_MULTIPLE_INSTANCES) { | 63 if (quirks_ & PLUGIN_QUIRK_DONT_ALLOW_MULTIPLE_INSTANCES) { |
| 63 NPAPI::PluginLib* plugin_lib = instance()->plugin_lib(); | 64 NPAPI::PluginLib* plugin_lib = instance()->plugin_lib(); |
| 64 if (plugin_lib->instance_count() > 1) { | 65 if (plugin_lib->instance_count() > 1) { |
| 65 return false; | 66 return false; |
| 66 } | 67 } |
| 67 } | 68 } |
| 68 | 69 |
| 69 if (quirks_ & PLUGIN_QUIRK_DIE_AFTER_UNLOAD) | 70 if (quirks_ & PLUGIN_QUIRK_DIE_AFTER_UNLOAD) |
| 70 webkit_glue::SetForcefullyTerminatePluginProcess(true); | 71 webkit_glue::SetForcefullyTerminatePluginProcess(true); |
| 71 | 72 |
| 72 bool start_result = instance_->Start(url, argn, argv, argc, load_manually); | 73 int argc = 0; |
| 74 scoped_array<char*> argn(new char*[arg_names.size()]); |
| 75 scoped_array<char*> argv(new char*[arg_names.size()]); |
| 76 for (size_t i = 0; i < arg_names.size(); ++i) { |
| 77 if (quirks_ & PLUGIN_QUIRK_NO_WINDOWLESS && |
| 78 LowerCaseEqualsASCII(arg_names[i], "windowlessvideo")) { |
| 79 continue; |
| 80 } |
| 81 argn[argc] = const_cast<char*>(arg_names[i].c_str()); |
| 82 argv[argc] = const_cast<char*>(arg_values[i].c_str()); |
| 83 argc++; |
| 84 } |
| 85 |
| 86 bool start_result = instance_->Start( |
| 87 url, argn.get(), argv.get(), argc, load_manually); |
| 73 | 88 |
| 74 NPAPI::PluginInstance::SetInitializingInstance(old_instance); | 89 NPAPI::PluginInstance::SetInitializingInstance(old_instance); |
| 75 | 90 |
| 76 if (!start_result) | 91 if (!start_result) |
| 77 return false; | 92 return false; |
| 78 | 93 |
| 79 windowless_ = instance_->windowless(); | 94 windowless_ = instance_->windowless(); |
| 80 if (!windowless_) { | 95 if (!windowless_) { |
| 81 if (!WindowedCreatePlugin()) | 96 if (!WindowedCreatePlugin()) |
| 82 return false; | 97 return false; |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 | 220 |
| 206 return plugin_stream->AsResourceClient(); | 221 return plugin_stream->AsResourceClient(); |
| 207 } | 222 } |
| 208 | 223 |
| 209 std::string mime_type; | 224 std::string mime_type; |
| 210 NPAPI::PluginStreamUrl *stream = instance()->CreateStream( | 225 NPAPI::PluginStreamUrl *stream = instance()->CreateStream( |
| 211 resource_id, url, mime_type, notify_needed, | 226 resource_id, url, mime_type, notify_needed, |
| 212 reinterpret_cast<void*>(notify_data)); | 227 reinterpret_cast<void*>(notify_data)); |
| 213 return stream; | 228 return stream; |
| 214 } | 229 } |
| OLD | NEW |