| 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 | |
| 250 // Set the container before Initialize because the plugin may | 246 // Set the container before Initialize because the plugin may |
| 251 // synchronously call NPN_GetValue to get its container, or make calls | 247 // synchronously call NPN_GetValue to get its container during its |
| 252 // passing script objects that need to be tracked, during initialization. | 248 // initialization. |
| 253 SetContainer(container); | 249 SetContainer(container); |
| 254 | |
| 255 bool ok = plugin_delegate->Initialize( | 250 bool ok = plugin_delegate->Initialize( |
| 256 plugin_url_, arg_names_, arg_values_, this, load_manually_); | 251 plugin_url_, arg_names_, arg_values_, this, load_manually_); |
| 257 if (!ok) { | 252 if (!ok) { |
| 258 LOG(ERROR) << "Couldn't initialize plug-in"; | 253 LOG(ERROR) << "Couldn't initialize plug-in"; |
| 259 plugin_delegate->PluginDestroyed(); | 254 plugin_delegate->PluginDestroyed(); |
| 260 | 255 |
| 261 WebKit::WebPlugin* replacement_plugin = | 256 WebKit::WebPlugin* replacement_plugin = |
| 262 page_delegate_->CreatePluginReplacement(file_path_); | 257 page_delegate_->CreatePluginReplacement(file_path_); |
| 263 if (!replacement_plugin || !replacement_plugin->initialize(container)) | 258 if (!replacement_plugin || !replacement_plugin->initialize(container)) |
| 264 return false; | 259 return false; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 278 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); | 273 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); |
| 279 } | 274 } |
| 280 | 275 |
| 281 NPObject* WebPluginImpl::scriptableObject() { | 276 NPObject* WebPluginImpl::scriptableObject() { |
| 282 if (!delegate_) | 277 if (!delegate_) |
| 283 return NULL; | 278 return NULL; |
| 284 | 279 |
| 285 return delegate_->GetPluginScriptableObject(); | 280 return delegate_->GetPluginScriptableObject(); |
| 286 } | 281 } |
| 287 | 282 |
| 288 NPP WebPluginImpl::pluginNPP() { | |
| 289 return npp_; | |
| 290 } | |
| 291 | |
| 292 bool WebPluginImpl::getFormValue(WebKit::WebString& value) { | 283 bool WebPluginImpl::getFormValue(WebKit::WebString& value) { |
| 293 if (!delegate_) | 284 if (!delegate_) |
| 294 return false; | 285 return false; |
| 295 base::string16 form_value; | 286 base::string16 form_value; |
| 296 if (!delegate_->GetFormValue(&form_value)) | 287 if (!delegate_->GetFormValue(&form_value)) |
| 297 return false; | 288 return false; |
| 298 value = form_value; | 289 value = form_value; |
| 299 return true; | 290 return true; |
| 300 } | 291 } |
| 301 | 292 |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 486 const WebPluginParams& params, | 477 const WebPluginParams& params, |
| 487 const base::FilePath& file_path, | 478 const base::FilePath& file_path, |
| 488 const base::WeakPtr<WebPluginPageDelegate>& page_delegate) | 479 const base::WeakPtr<WebPluginPageDelegate>& page_delegate) |
| 489 : windowless_(false), | 480 : windowless_(false), |
| 490 window_(gfx::kNullPluginWindow), | 481 window_(gfx::kNullPluginWindow), |
| 491 accepts_input_events_(false), | 482 accepts_input_events_(false), |
| 492 page_delegate_(page_delegate), | 483 page_delegate_(page_delegate), |
| 493 webframe_(webframe), | 484 webframe_(webframe), |
| 494 delegate_(NULL), | 485 delegate_(NULL), |
| 495 container_(NULL), | 486 container_(NULL), |
| 496 npp_(NULL), | |
| 497 plugin_url_(params.url), | 487 plugin_url_(params.url), |
| 498 load_manually_(params.loadManually), | 488 load_manually_(params.loadManually), |
| 499 first_geometry_update_(true), | 489 first_geometry_update_(true), |
| 500 ignore_response_error_(false), | 490 ignore_response_error_(false), |
| 501 file_path_(file_path), | 491 file_path_(file_path), |
| 502 mime_type_(UTF16ToASCII(params.mimeType)), | 492 mime_type_(UTF16ToASCII(params.mimeType)), |
| 503 weak_factory_(this) { | 493 weak_factory_(this) { |
| 504 DCHECK_EQ(params.attributeNames.size(), params.attributeValues.size()); | 494 DCHECK_EQ(params.attributeNames.size(), params.attributeValues.size()); |
| 505 StringToLowerASCII(&mime_type_); | 495 StringToLowerASCII(&mime_type_); |
| 506 | 496 |
| (...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1058 RemoveClient(i); | 1048 RemoveClient(i); |
| 1059 return; | 1049 return; |
| 1060 } | 1050 } |
| 1061 } | 1051 } |
| 1062 } | 1052 } |
| 1063 | 1053 |
| 1064 void WebPluginImpl::SetContainer(WebPluginContainer* container) { | 1054 void WebPluginImpl::SetContainer(WebPluginContainer* container) { |
| 1065 if (!container) | 1055 if (!container) |
| 1066 TearDownPluginInstance(NULL); | 1056 TearDownPluginInstance(NULL); |
| 1067 container_ = container; | 1057 container_ = container; |
| 1068 if (container_) | |
| 1069 container_->allowScriptObjects(); | |
| 1070 } | 1058 } |
| 1071 | 1059 |
| 1072 void WebPluginImpl::HandleURLRequest(const char* url, | 1060 void WebPluginImpl::HandleURLRequest(const char* url, |
| 1073 const char* method, | 1061 const char* method, |
| 1074 const char* target, | 1062 const char* target, |
| 1075 const char* buf, | 1063 const char* buf, |
| 1076 unsigned int len, | 1064 unsigned int len, |
| 1077 int notify_id, | 1065 int notify_id, |
| 1078 bool popups_allowed, | 1066 bool popups_allowed, |
| 1079 bool notify_redirects) { | 1067 bool notify_redirects) { |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1338 | 1326 |
| 1339 // The plugin move sequences accumulated via DidMove are sent to the browser | 1327 // The plugin move sequences accumulated via DidMove are sent to the browser |
| 1340 // whenever the renderer paints. Force a paint here to ensure that changes | 1328 // whenever the renderer paints. Force a paint here to ensure that changes |
| 1341 // to the plugin window are propagated to the browser. | 1329 // to the plugin window are propagated to the browser. |
| 1342 container_->invalidate(); | 1330 container_->invalidate(); |
| 1343 return true; | 1331 return true; |
| 1344 } | 1332 } |
| 1345 | 1333 |
| 1346 void WebPluginImpl::TearDownPluginInstance( | 1334 void WebPluginImpl::TearDownPluginInstance( |
| 1347 WebURLLoader* loader_to_ignore) { | 1335 WebURLLoader* loader_to_ignore) { |
| 1348 // JavaScript garbage collection may cause plugin script object references to | 1336 // The container maintains a list of JSObjects which are related to this |
| 1349 // be retained long after the plugin is destroyed. Some plugins won't cope | 1337 // plugin. Tell the frame we're gone so that it can invalidate all of |
| 1350 // with their objects being released after they've been destroyed, and once | 1338 // those sub JSObjects. |
| 1351 // we've actually unloaded the plugin the object's releaseobject() code may | |
| 1352 // no longer be in memory. The container tracks the plugin's objects and lets | |
| 1353 // us invalidate them, releasing the references to them held by the JavaScript | |
| 1354 // runtime. | |
| 1355 if (container_) { | 1339 if (container_) { |
| 1356 container_->clearScriptObjects(); | 1340 container_->clearScriptObjects(); |
| 1357 container_->setWebLayer(NULL); | 1341 container_->setWebLayer(NULL); |
| 1358 } | 1342 } |
| 1359 | 1343 |
| 1360 // Call PluginDestroyed() first to prevent the plugin from calling us back | |
| 1361 // in the middle of tearing down the render tree. | |
| 1362 if (delegate_) { | 1344 if (delegate_) { |
| 1363 // The plugin may call into the browser and pass script objects even during | 1345 // Call PluginDestroyed() first to prevent the plugin from calling us back |
| 1364 // teardown, so temporarily re-enable plugin script objects. | 1346 // in the middle of tearing down the render tree. |
| 1365 DCHECK(container_); | |
| 1366 container_->allowScriptObjects(); | |
| 1367 | |
| 1368 delegate_->PluginDestroyed(); | 1347 delegate_->PluginDestroyed(); |
| 1369 delegate_ = NULL; | 1348 delegate_ = NULL; |
| 1370 | |
| 1371 // Invalidate any script objects created during teardown here, before the | |
| 1372 // plugin might actually be unloaded. | |
| 1373 container_->clearScriptObjects(); | |
| 1374 } | 1349 } |
| 1375 | 1350 |
| 1376 // Cancel any pending requests because otherwise this deleted object will | 1351 // Cancel any pending requests because otherwise this deleted object will |
| 1377 // be called by the ResourceDispatcher. | 1352 // be called by the ResourceDispatcher. |
| 1378 std::vector<ClientInfo>::iterator client_index = clients_.begin(); | 1353 std::vector<ClientInfo>::iterator client_index = clients_.begin(); |
| 1379 while (client_index != clients_.end()) { | 1354 while (client_index != clients_.end()) { |
| 1380 ClientInfo& client_info = *client_index; | 1355 ClientInfo& client_info = *client_index; |
| 1381 | 1356 |
| 1382 if (loader_to_ignore == client_info.loader) { | 1357 if (loader_to_ignore == client_info.loader) { |
| 1383 client_index++; | 1358 client_index++; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1407 webframe_->setReferrerForRequest(*request, plugin_url_); | 1382 webframe_->setReferrerForRequest(*request, plugin_url_); |
| 1408 break; | 1383 break; |
| 1409 | 1384 |
| 1410 default: | 1385 default: |
| 1411 break; | 1386 break; |
| 1412 } | 1387 } |
| 1413 } | 1388 } |
| 1414 | 1389 |
| 1415 } // namespace npapi | 1390 } // namespace npapi |
| 1416 } // namespace webkit | 1391 } // namespace webkit |
| OLD | NEW |