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/npapi/webplugin_impl.h" | 5 #include "webkit/plugins/npapi/webplugin_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/debug/crash_logging.h" | 8 #include "base/debug/crash_logging.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/linked_ptr.h" | 10 #include "base/memory/linked_ptr.h" |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 if (!page_delegate_) { | 236 if (!page_delegate_) { |
237 LOG(ERROR) << "No page delegate"; | 237 LOG(ERROR) << "No page delegate"; |
238 return false; | 238 return false; |
239 } | 239 } |
240 | 240 |
241 WebPluginDelegate* plugin_delegate = page_delegate_->CreatePluginDelegate( | 241 WebPluginDelegate* plugin_delegate = page_delegate_->CreatePluginDelegate( |
242 file_path_, mime_type_); | 242 file_path_, mime_type_); |
243 if (!plugin_delegate) | 243 if (!plugin_delegate) |
244 return false; | 244 return false; |
245 | 245 |
| 246 // Store the plugin's unique identifier, used by the container to track its |
| 247 // script objects. |
| 248 npp_ = plugin_delegate->GetPluginNPP(); |
| 249 |
246 // Set the container before Initialize because the plugin may | 250 // Set the container before Initialize because the plugin may |
247 // synchronously call NPN_GetValue to get its container during its | 251 // synchronously call NPN_GetValue to get its container, or make calls |
248 // initialization. | 252 // passing script objects that need to be tracked, during initialization. |
249 SetContainer(container); | 253 SetContainer(container); |
| 254 |
250 bool ok = plugin_delegate->Initialize( | 255 bool ok = plugin_delegate->Initialize( |
251 plugin_url_, arg_names_, arg_values_, this, load_manually_); | 256 plugin_url_, arg_names_, arg_values_, this, load_manually_); |
252 if (!ok) { | 257 if (!ok) { |
253 LOG(ERROR) << "Couldn't initialize plug-in"; | 258 LOG(ERROR) << "Couldn't initialize plug-in"; |
254 plugin_delegate->PluginDestroyed(); | 259 plugin_delegate->PluginDestroyed(); |
255 | 260 |
256 WebKit::WebPlugin* replacement_plugin = | 261 WebKit::WebPlugin* replacement_plugin = |
257 page_delegate_->CreatePluginReplacement(file_path_); | 262 page_delegate_->CreatePluginReplacement(file_path_); |
258 if (!replacement_plugin || !replacement_plugin->initialize(container)) | 263 if (!replacement_plugin || !replacement_plugin->initialize(container)) |
259 return false; | 264 return false; |
(...skipping 13 matching lines...) Expand all Loading... |
273 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); | 278 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); |
274 } | 279 } |
275 | 280 |
276 NPObject* WebPluginImpl::scriptableObject() { | 281 NPObject* WebPluginImpl::scriptableObject() { |
277 if (!delegate_) | 282 if (!delegate_) |
278 return NULL; | 283 return NULL; |
279 | 284 |
280 return delegate_->GetPluginScriptableObject(); | 285 return delegate_->GetPluginScriptableObject(); |
281 } | 286 } |
282 | 287 |
| 288 NPP WebPluginImpl::pluginNPP() { |
| 289 return npp_; |
| 290 } |
| 291 |
283 bool WebPluginImpl::getFormValue(WebKit::WebString& value) { | 292 bool WebPluginImpl::getFormValue(WebKit::WebString& value) { |
284 if (!delegate_) | 293 if (!delegate_) |
285 return false; | 294 return false; |
286 base::string16 form_value; | 295 base::string16 form_value; |
287 if (!delegate_->GetFormValue(&form_value)) | 296 if (!delegate_->GetFormValue(&form_value)) |
288 return false; | 297 return false; |
289 value = form_value; | 298 value = form_value; |
290 return true; | 299 return true; |
291 } | 300 } |
292 | 301 |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
468 const WebPluginParams& params, | 477 const WebPluginParams& params, |
469 const base::FilePath& file_path, | 478 const base::FilePath& file_path, |
470 const base::WeakPtr<WebPluginPageDelegate>& page_delegate) | 479 const base::WeakPtr<WebPluginPageDelegate>& page_delegate) |
471 : windowless_(false), | 480 : windowless_(false), |
472 window_(gfx::kNullPluginWindow), | 481 window_(gfx::kNullPluginWindow), |
473 accepts_input_events_(false), | 482 accepts_input_events_(false), |
474 page_delegate_(page_delegate), | 483 page_delegate_(page_delegate), |
475 webframe_(webframe), | 484 webframe_(webframe), |
476 delegate_(NULL), | 485 delegate_(NULL), |
477 container_(NULL), | 486 container_(NULL), |
| 487 npp_(NULL), |
478 plugin_url_(params.url), | 488 plugin_url_(params.url), |
479 load_manually_(params.loadManually), | 489 load_manually_(params.loadManually), |
480 first_geometry_update_(true), | 490 first_geometry_update_(true), |
481 ignore_response_error_(false), | 491 ignore_response_error_(false), |
482 file_path_(file_path), | 492 file_path_(file_path), |
483 mime_type_(UTF16ToASCII(params.mimeType)), | 493 mime_type_(UTF16ToASCII(params.mimeType)), |
484 weak_factory_(this) { | 494 weak_factory_(this) { |
485 DCHECK_EQ(params.attributeNames.size(), params.attributeValues.size()); | 495 DCHECK_EQ(params.attributeNames.size(), params.attributeValues.size()); |
486 StringToLowerASCII(&mime_type_); | 496 StringToLowerASCII(&mime_type_); |
487 | 497 |
(...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1039 RemoveClient(i); | 1049 RemoveClient(i); |
1040 return; | 1050 return; |
1041 } | 1051 } |
1042 } | 1052 } |
1043 } | 1053 } |
1044 | 1054 |
1045 void WebPluginImpl::SetContainer(WebPluginContainer* container) { | 1055 void WebPluginImpl::SetContainer(WebPluginContainer* container) { |
1046 if (!container) | 1056 if (!container) |
1047 TearDownPluginInstance(NULL); | 1057 TearDownPluginInstance(NULL); |
1048 container_ = container; | 1058 container_ = container; |
| 1059 if (container_) |
| 1060 container_->allowScriptObjects(); |
1049 } | 1061 } |
1050 | 1062 |
1051 void WebPluginImpl::HandleURLRequest(const char* url, | 1063 void WebPluginImpl::HandleURLRequest(const char* url, |
1052 const char* method, | 1064 const char* method, |
1053 const char* target, | 1065 const char* target, |
1054 const char* buf, | 1066 const char* buf, |
1055 unsigned int len, | 1067 unsigned int len, |
1056 int notify_id, | 1068 int notify_id, |
1057 bool popups_allowed, | 1069 bool popups_allowed, |
1058 bool notify_redirects) { | 1070 bool notify_redirects) { |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1317 | 1329 |
1318 // The plugin move sequences accumulated via DidMove are sent to the browser | 1330 // The plugin move sequences accumulated via DidMove are sent to the browser |
1319 // whenever the renderer paints. Force a paint here to ensure that changes | 1331 // whenever the renderer paints. Force a paint here to ensure that changes |
1320 // to the plugin window are propagated to the browser. | 1332 // to the plugin window are propagated to the browser. |
1321 container_->invalidate(); | 1333 container_->invalidate(); |
1322 return true; | 1334 return true; |
1323 } | 1335 } |
1324 | 1336 |
1325 void WebPluginImpl::TearDownPluginInstance( | 1337 void WebPluginImpl::TearDownPluginInstance( |
1326 WebURLLoader* loader_to_ignore) { | 1338 WebURLLoader* loader_to_ignore) { |
1327 // The container maintains a list of JSObjects which are related to this | 1339 // JavaScript garbage collection may cause plugin script object references to |
1328 // plugin. Tell the frame we're gone so that it can invalidate all of | 1340 // be retained long after the plugin is destroyed. Some plugins won't cope |
1329 // those sub JSObjects. | 1341 // with their objects being released after they've been destroyed, and once |
| 1342 // we've actually unloaded the plugin the object's releaseobject() code may |
| 1343 // no longer be in memory. The container tracks the plugin's objects and lets |
| 1344 // us invalidate them, releasing the references to them held by the JavaScript |
| 1345 // runtime. |
1330 if (container_) { | 1346 if (container_) { |
1331 container_->clearScriptObjects(); | 1347 container_->clearScriptObjects(); |
1332 container_->setWebLayer(NULL); | 1348 container_->setWebLayer(NULL); |
1333 } | 1349 } |
1334 | 1350 |
| 1351 // Call PluginDestroyed() first to prevent the plugin from calling us back |
| 1352 // in the middle of tearing down the render tree. |
1335 if (delegate_) { | 1353 if (delegate_) { |
1336 // Call PluginDestroyed() first to prevent the plugin from calling us back | 1354 // The plugin may call into the browser and pass script objects even during |
1337 // in the middle of tearing down the render tree. | 1355 // teardown, so temporarily re-enable plugin script objects. |
| 1356 DCHECK(container_); |
| 1357 container_->allowScriptObjects(); |
| 1358 |
1338 delegate_->PluginDestroyed(); | 1359 delegate_->PluginDestroyed(); |
1339 delegate_ = NULL; | 1360 delegate_ = NULL; |
| 1361 |
| 1362 // Invalidate any script objects created during teardown here, before the |
| 1363 // plugin might actually be unloaded. |
| 1364 container_->clearScriptObjects(); |
1340 } | 1365 } |
1341 | 1366 |
1342 // Cancel any pending requests because otherwise this deleted object will | 1367 // Cancel any pending requests because otherwise this deleted object will |
1343 // be called by the ResourceDispatcher. | 1368 // be called by the ResourceDispatcher. |
1344 std::vector<ClientInfo>::iterator client_index = clients_.begin(); | 1369 std::vector<ClientInfo>::iterator client_index = clients_.begin(); |
1345 while (client_index != clients_.end()) { | 1370 while (client_index != clients_.end()) { |
1346 ClientInfo& client_info = *client_index; | 1371 ClientInfo& client_info = *client_index; |
1347 | 1372 |
1348 if (loader_to_ignore == client_info.loader) { | 1373 if (loader_to_ignore == client_info.loader) { |
1349 client_index++; | 1374 client_index++; |
(...skipping 23 matching lines...) Expand all Loading... |
1373 webframe_->setReferrerForRequest(*request, plugin_url_); | 1398 webframe_->setReferrerForRequest(*request, plugin_url_); |
1374 break; | 1399 break; |
1375 | 1400 |
1376 default: | 1401 default: |
1377 break; | 1402 break; |
1378 } | 1403 } |
1379 } | 1404 } |
1380 | 1405 |
1381 } // namespace npapi | 1406 } // namespace npapi |
1382 } // namespace webkit | 1407 } // namespace webkit |
OLD | NEW |