Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(334)

Side by Side Diff: chrome/plugin/webplugin_delegate_stub.cc

Issue 258026: Fix scripting during NPP_Destroy. Note that if the plugin is making a call t... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/plugin/webplugin_delegate_stub.h" 5 #include "chrome/plugin/webplugin_delegate_stub.h"
6 6
7 #include "build/build_config.h" 7 #include "build/build_config.h"
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "chrome/common/child_process_logging.h" 10 #include "chrome/common/child_process_logging.h"
11 #include "chrome/common/chrome_switches.h" 11 #include "chrome/common/chrome_switches.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 WebPluginDelegateImpl* delegate_; 45 WebPluginDelegateImpl* delegate_;
46 WebPlugin* webplugin_; 46 WebPlugin* webplugin_;
47 }; 47 };
48 48
49 WebPluginDelegateStub::WebPluginDelegateStub( 49 WebPluginDelegateStub::WebPluginDelegateStub(
50 const std::string& mime_type, int instance_id, PluginChannel* channel) : 50 const std::string& mime_type, int instance_id, PluginChannel* channel) :
51 mime_type_(mime_type), 51 mime_type_(mime_type),
52 instance_id_(instance_id), 52 instance_id_(instance_id),
53 channel_(channel), 53 channel_(channel),
54 delegate_(NULL), 54 delegate_(NULL),
55 webplugin_(NULL) { 55 webplugin_(NULL),
56 in_destructor_(false) {
56 DCHECK(channel); 57 DCHECK(channel);
57 } 58 }
58 59
59 WebPluginDelegateStub::~WebPluginDelegateStub() { 60 WebPluginDelegateStub::~WebPluginDelegateStub() {
61 in_destructor_ = true;
60 child_process_logging::ScopedActiveURLSetter url_setter(page_url_); 62 child_process_logging::ScopedActiveURLSetter url_setter(page_url_);
61 63
62 if (channel_->in_send()) { 64 if (channel_->in_send()) {
63 // The delegate or an npobject is in the callstack, so don't delete it 65 // The delegate or an npobject is in the callstack, so don't delete it
64 // right away. 66 // right away.
65 MessageLoop::current()->PostNonNestableTask(FROM_HERE, 67 MessageLoop::current()->PostNonNestableTask(FROM_HERE,
66 new FinishDestructionTask(delegate_, webplugin_)); 68 new FinishDestructionTask(delegate_, webplugin_));
67 } else { 69 } else {
68 // Safe to delete right away. 70 // Safe to delete right away.
69 if (delegate_) 71 if (delegate_)
70 delegate_->PluginDestroyed(); 72 delegate_->PluginDestroyed();
71 73
72 delete webplugin_; 74 delete webplugin_;
73 } 75 }
74 } 76 }
75 77
76 void WebPluginDelegateStub::OnMessageReceived(const IPC::Message& msg) { 78 void WebPluginDelegateStub::OnMessageReceived(const IPC::Message& msg) {
77 child_process_logging::ScopedActiveURLSetter url_setter(page_url_); 79 child_process_logging::ScopedActiveURLSetter url_setter(page_url_);
78 80
79 // A plugin can execute a script to delete itself in any of its NPP methods. 81 // A plugin can execute a script to delete itself in any of its NPP methods.
80 // Hold an extra reference to ourself so that if this does occur and we're 82 // Hold an extra reference to ourself so that if this does occur and we're
81 // handling a sync message, we don't crash when attempting to send a reply. 83 // handling a sync message, we don't crash when attempting to send a reply.
82 AddRef(); 84 // The exception to this is when we're already in the destructor.
85 if (!in_destructor_)
86 AddRef();
83 87
84 IPC_BEGIN_MESSAGE_MAP(WebPluginDelegateStub, msg) 88 IPC_BEGIN_MESSAGE_MAP(WebPluginDelegateStub, msg)
85 IPC_MESSAGE_HANDLER(PluginMsg_Init, OnInit) 89 IPC_MESSAGE_HANDLER(PluginMsg_Init, OnInit)
86 IPC_MESSAGE_HANDLER(PluginMsg_WillSendRequest, OnWillSendRequest) 90 IPC_MESSAGE_HANDLER(PluginMsg_WillSendRequest, OnWillSendRequest)
87 IPC_MESSAGE_HANDLER(PluginMsg_DidReceiveResponse, OnDidReceiveResponse) 91 IPC_MESSAGE_HANDLER(PluginMsg_DidReceiveResponse, OnDidReceiveResponse)
88 IPC_MESSAGE_HANDLER(PluginMsg_DidReceiveData, OnDidReceiveData) 92 IPC_MESSAGE_HANDLER(PluginMsg_DidReceiveData, OnDidReceiveData)
89 IPC_MESSAGE_HANDLER(PluginMsg_DidFinishLoading, OnDidFinishLoading) 93 IPC_MESSAGE_HANDLER(PluginMsg_DidFinishLoading, OnDidFinishLoading)
90 IPC_MESSAGE_HANDLER(PluginMsg_DidFail, OnDidFail) 94 IPC_MESSAGE_HANDLER(PluginMsg_DidFail, OnDidFail)
91 IPC_MESSAGE_HANDLER(PluginMsg_DidFinishLoadWithReason, 95 IPC_MESSAGE_HANDLER(PluginMsg_DidFinishLoadWithReason,
92 OnDidFinishLoadWithReason) 96 OnDidFinishLoadWithReason)
(...skipping 13 matching lines...) Expand all
106 IPC_MESSAGE_HANDLER(PluginMsg_DidReceiveManualData, OnDidReceiveManualData) 110 IPC_MESSAGE_HANDLER(PluginMsg_DidReceiveManualData, OnDidReceiveManualData)
107 IPC_MESSAGE_HANDLER(PluginMsg_DidFinishManualLoading, 111 IPC_MESSAGE_HANDLER(PluginMsg_DidFinishManualLoading,
108 OnDidFinishManualLoading) 112 OnDidFinishManualLoading)
109 IPC_MESSAGE_HANDLER(PluginMsg_DidManualLoadFail, OnDidManualLoadFail) 113 IPC_MESSAGE_HANDLER(PluginMsg_DidManualLoadFail, OnDidManualLoadFail)
110 IPC_MESSAGE_HANDLER(PluginMsg_InstallMissingPlugin, OnInstallMissingPlugin) 114 IPC_MESSAGE_HANDLER(PluginMsg_InstallMissingPlugin, OnInstallMissingPlugin)
111 IPC_MESSAGE_HANDLER(PluginMsg_HandleURLRequestReply, 115 IPC_MESSAGE_HANDLER(PluginMsg_HandleURLRequestReply,
112 OnHandleURLRequestReply) 116 OnHandleURLRequestReply)
113 IPC_MESSAGE_UNHANDLED_ERROR() 117 IPC_MESSAGE_UNHANDLED_ERROR()
114 IPC_END_MESSAGE_MAP() 118 IPC_END_MESSAGE_MAP()
115 119
116 Release(); 120 if (!in_destructor_)
121 Release();
117 } 122 }
118 123
119 bool WebPluginDelegateStub::Send(IPC::Message* msg) { 124 bool WebPluginDelegateStub::Send(IPC::Message* msg) {
120 return channel_->Send(msg); 125 return channel_->Send(msg);
121 } 126 }
122 127
123 void WebPluginDelegateStub::OnInit(const PluginMsg_Init_Params& params, 128 void WebPluginDelegateStub::OnInit(const PluginMsg_Init_Params& params,
124 bool* result) { 129 bool* result) {
125 page_url_ = params.page_url; 130 page_url_ = params.page_url;
126 child_process_logging::ScopedActiveURLSetter url_setter(page_url_); 131 child_process_logging::ScopedActiveURLSetter url_setter(page_url_);
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 365
361 void WebPluginDelegateStub::OnHandleURLRequestReply( 366 void WebPluginDelegateStub::OnHandleURLRequestReply(
362 const PluginMsg_URLRequestReply_Params& params) { 367 const PluginMsg_URLRequestReply_Params& params) {
363 WebPluginResourceClient* resource_client = 368 WebPluginResourceClient* resource_client =
364 delegate_->CreateResourceClient(params.resource_id, params.url, 369 delegate_->CreateResourceClient(params.resource_id, params.url,
365 params.notify_needed, 370 params.notify_needed,
366 params.notify_data, 371 params.notify_data,
367 params.stream); 372 params.stream);
368 webplugin_->OnResourceCreated(params.resource_id, resource_client); 373 webplugin_->OnResourceCreated(params.resource_id, resource_client);
369 } 374 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698