Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "chrome/renderer/webplugin_delegate_proxy.h" | 5 #include "chrome/renderer/webplugin_delegate_proxy.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "app/gfx/canvas.h" | 9 #include "app/gfx/canvas.h" |
| 10 #include "app/l10n_util.h" | 10 #include "app/l10n_util.h" |
| 11 #include "app/resource_bundle.h" | 11 #include "app/resource_bundle.h" |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 158 WebPluginDelegateProxy::WebPluginDelegateProxy( | 158 WebPluginDelegateProxy::WebPluginDelegateProxy( |
| 159 const std::string& mime_type, | 159 const std::string& mime_type, |
| 160 const base::WeakPtr<RenderView>& render_view) | 160 const base::WeakPtr<RenderView>& render_view) |
| 161 : render_view_(render_view), | 161 : render_view_(render_view), |
| 162 plugin_(NULL), | 162 plugin_(NULL), |
| 163 windowless_(false), | 163 windowless_(false), |
| 164 window_(NULL), | 164 window_(NULL), |
| 165 mime_type_(mime_type), | 165 mime_type_(mime_type), |
| 166 instance_id_(MSG_ROUTING_NONE), | 166 instance_id_(MSG_ROUTING_NONE), |
| 167 npobject_(NULL), | 167 npobject_(NULL), |
| 168 window_script_object_(NULL), | |
| 169 sad_plugin_(NULL), | 168 sad_plugin_(NULL), |
| 170 invalidate_pending_(false), | 169 invalidate_pending_(false), |
| 171 transparent_(false), | 170 transparent_(false), |
| 172 page_url_(render_view_->webview()->mainFrame()->url()) { | 171 page_url_(render_view_->webview()->mainFrame()->url()) { |
| 173 } | 172 } |
| 174 | 173 |
| 175 WebPluginDelegateProxy::~WebPluginDelegateProxy() { | 174 WebPluginDelegateProxy::~WebPluginDelegateProxy() { |
| 176 } | 175 } |
| 177 | 176 |
| 178 void WebPluginDelegateProxy::PluginDestroyed() { | 177 void WebPluginDelegateProxy::PluginDestroyed() { |
| 179 if (window_) { | 178 if (window_) |
| 180 WillDestroyWindow(); | 179 WillDestroyWindow(); |
| 181 } | |
| 182 plugin_ = NULL; | |
|
jam
2009/10/06 07:10:48
setting plugin_ to null and calling RemoveRoute be
| |
| 183 | |
| 184 if (npobject_) { | |
| 185 // When we destroy the plugin instance, the NPObjectStub NULLs out its | |
| 186 // pointer to the npobject (see NPObjectStub::OnChannelError). Therefore, | |
| 187 // we release the object before destroying the instance to avoid leaking. | |
| 188 WebBindings::releaseObject(npobject_); | |
|
jam
2009/10/06 07:10:48
this was added in http://chrome-corpsvn.mtv/viewvc
| |
| 189 npobject_ = NULL; | |
| 190 } | |
| 191 | |
| 192 if (window_script_object_) { | |
| 193 // The ScriptController deallocates this object independent of its ref count | |
| 194 // to avoid leaks if the plugin forgets to release it. So mark the object | |
| 195 // invalid to avoid accessing it past this point. | |
| 196 window_script_object_->set_proxy(NULL); | |
| 197 window_script_object_->set_invalid(); | |
| 198 } | |
| 199 | 180 |
| 200 if (channel_host_) { | 181 if (channel_host_) { |
| 182 Send(new PluginMsg_DestroyInstance(instance_id_)); | |
| 183 | |
| 184 // Must remove the route after sending the destroy message, since | |
| 185 // RemoveRoute can lead to all the outstanding NPObjects being told the | |
| 186 // channel went away if this was the last instance. | |
| 201 channel_host_->RemoveRoute(instance_id_); | 187 channel_host_->RemoveRoute(instance_id_); |
| 202 Send(new PluginMsg_DestroyInstance(instance_id_)); | 188 |
| 203 // Release the channel host now. If we are is the last reference to the | 189 // Release the channel host now. If we are is the last reference to the |
| 204 // channel, this avoids a race where this renderer asks a new connection to | 190 // channel, this avoids a race where this renderer asks a new connection to |
| 205 // the same plugin between now and the time 'this' is actually deleted. | 191 // the same plugin between now and the time 'this' is actually deleted. |
| 206 // Destroying the channel host is what releases the channel name -> FD | 192 // Destroying the channel host is what releases the channel name -> FD |
| 207 // association on POSIX, and if we ask for a new connection before it is | 193 // association on POSIX, and if we ask for a new connection before it is |
| 208 // released, the plugin will give us a new FD, and we'll assert when trying | 194 // released, the plugin will give us a new FD, and we'll assert when trying |
| 209 // to associate it with the channel name. | 195 // to associate it with the channel name. |
| 210 channel_host_ = NULL; | 196 channel_host_ = NULL; |
| 211 } | 197 } |
| 212 | 198 |
| 199 if (window_script_object_) { | |
| 200 // The ScriptController deallocates this object independent of its ref count | |
| 201 // to avoid leaks if the plugin forgets to release it. So mark the object | |
| 202 // invalid to avoid accessing it past this point. Note: only do this after | |
| 203 // the DestroyInstance message in case the window object is scripted by the | |
| 204 // plugin in NPP_Destroy. | |
| 205 window_script_object_->OnPluginDestroyed(); | |
| 206 } | |
| 207 | |
| 208 plugin_ = NULL; | |
| 209 | |
| 213 MessageLoop::current()->DeleteSoon(FROM_HERE, this); | 210 MessageLoop::current()->DeleteSoon(FROM_HERE, this); |
| 214 } | 211 } |
| 215 | 212 |
| 216 bool WebPluginDelegateProxy::Initialize(const GURL& url, | 213 bool WebPluginDelegateProxy::Initialize(const GURL& url, |
| 217 const std::vector<std::string>& arg_names, | 214 const std::vector<std::string>& arg_names, |
| 218 const std::vector<std::string>& arg_values, | 215 const std::vector<std::string>& arg_values, |
| 219 webkit_glue::WebPlugin* plugin, | 216 webkit_glue::WebPlugin* plugin, |
| 220 bool load_manually) { | 217 bool load_manually) { |
| 221 IPC::ChannelHandle channel_handle; | 218 IPC::ChannelHandle channel_handle; |
| 222 WebPluginInfo info; | 219 WebPluginInfo info; |
| (...skipping 598 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 821 *success = false; | 818 *success = false; |
| 822 NPObject* npobject = NULL; | 819 NPObject* npobject = NULL; |
| 823 if (plugin_) | 820 if (plugin_) |
| 824 npobject = plugin_->GetWindowScriptNPObject(); | 821 npobject = plugin_->GetWindowScriptNPObject(); |
| 825 | 822 |
| 826 if (!npobject) | 823 if (!npobject) |
| 827 return; | 824 return; |
| 828 | 825 |
| 829 // The stub will delete itself when the proxy tells it that it's released, or | 826 // The stub will delete itself when the proxy tells it that it's released, or |
| 830 // otherwise when the channel is closed. | 827 // otherwise when the channel is closed. |
| 831 NPObjectStub* stub = new NPObjectStub( | 828 window_script_object_ = (new NPObjectStub( |
| 832 npobject, channel_host_.get(), route_id, 0, page_url_); | 829 npobject, channel_host_.get(), route_id, 0, page_url_))->AsWeakPtr(); |
| 833 window_script_object_ = stub; | |
| 834 window_script_object_->set_proxy(this); | |
| 835 *success = true; | 830 *success = true; |
| 836 *npobject_ptr = reinterpret_cast<intptr_t>(npobject); | 831 *npobject_ptr = reinterpret_cast<intptr_t>(npobject); |
| 837 } | 832 } |
| 838 | 833 |
| 839 void WebPluginDelegateProxy::OnGetPluginElement( | 834 void WebPluginDelegateProxy::OnGetPluginElement( |
| 840 int route_id, bool* success, intptr_t* npobject_ptr) { | 835 int route_id, bool* success, intptr_t* npobject_ptr) { |
| 841 *success = false; | 836 *success = false; |
| 842 NPObject* npobject = NULL; | 837 NPObject* npobject = NULL; |
| 843 if (plugin_) | 838 if (plugin_) |
| 844 npobject = plugin_->GetPluginElement(); | 839 npobject = plugin_->GetPluginElement(); |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1059 intptr_t existing_stream, bool notify_needed, intptr_t notify_data) { | 1054 intptr_t existing_stream, bool notify_needed, intptr_t notify_data) { |
| 1060 plugin_->InitiateHTTPRangeRequest(url.c_str(), range_info.c_str(), | 1055 plugin_->InitiateHTTPRangeRequest(url.c_str(), range_info.c_str(), |
| 1061 existing_stream, notify_needed, | 1056 existing_stream, notify_needed, |
| 1062 notify_data); | 1057 notify_data); |
| 1063 } | 1058 } |
| 1064 | 1059 |
| 1065 void WebPluginDelegateProxy::OnDeferResourceLoading(int resource_id, | 1060 void WebPluginDelegateProxy::OnDeferResourceLoading(int resource_id, |
| 1066 bool defer) { | 1061 bool defer) { |
| 1067 plugin_->SetDeferResourceLoading(resource_id, defer); | 1062 plugin_->SetDeferResourceLoading(resource_id, defer); |
| 1068 } | 1063 } |
| OLD | NEW |