| 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 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 477 const WebPluginParams& params, | 486 const WebPluginParams& params, |
| 478 const base::FilePath& file_path, | 487 const base::FilePath& file_path, |
| 479 const base::WeakPtr<WebPluginPageDelegate>& page_delegate) | 488 const base::WeakPtr<WebPluginPageDelegate>& page_delegate) |
| 480 : windowless_(false), | 489 : windowless_(false), |
| 481 window_(gfx::kNullPluginWindow), | 490 window_(gfx::kNullPluginWindow), |
| 482 accepts_input_events_(false), | 491 accepts_input_events_(false), |
| 483 page_delegate_(page_delegate), | 492 page_delegate_(page_delegate), |
| 484 webframe_(webframe), | 493 webframe_(webframe), |
| 485 delegate_(NULL), | 494 delegate_(NULL), |
| 486 container_(NULL), | 495 container_(NULL), |
| 496 npp_(NULL), |
| 487 plugin_url_(params.url), | 497 plugin_url_(params.url), |
| 488 load_manually_(params.loadManually), | 498 load_manually_(params.loadManually), |
| 489 first_geometry_update_(true), | 499 first_geometry_update_(true), |
| 490 ignore_response_error_(false), | 500 ignore_response_error_(false), |
| 491 file_path_(file_path), | 501 file_path_(file_path), |
| 492 mime_type_(UTF16ToASCII(params.mimeType)), | 502 mime_type_(UTF16ToASCII(params.mimeType)), |
| 493 weak_factory_(this) { | 503 weak_factory_(this) { |
| 494 DCHECK_EQ(params.attributeNames.size(), params.attributeValues.size()); | 504 DCHECK_EQ(params.attributeNames.size(), params.attributeValues.size()); |
| 495 StringToLowerASCII(&mime_type_); | 505 StringToLowerASCII(&mime_type_); |
| 496 | 506 |
| (...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1048 RemoveClient(i); | 1058 RemoveClient(i); |
| 1049 return; | 1059 return; |
| 1050 } | 1060 } |
| 1051 } | 1061 } |
| 1052 } | 1062 } |
| 1053 | 1063 |
| 1054 void WebPluginImpl::SetContainer(WebPluginContainer* container) { | 1064 void WebPluginImpl::SetContainer(WebPluginContainer* container) { |
| 1055 if (!container) | 1065 if (!container) |
| 1056 TearDownPluginInstance(NULL); | 1066 TearDownPluginInstance(NULL); |
| 1057 container_ = container; | 1067 container_ = container; |
| 1068 if (container_) |
| 1069 container_->allowScriptObjects(); |
| 1058 } | 1070 } |
| 1059 | 1071 |
| 1060 void WebPluginImpl::HandleURLRequest(const char* url, | 1072 void WebPluginImpl::HandleURLRequest(const char* url, |
| 1061 const char* method, | 1073 const char* method, |
| 1062 const char* target, | 1074 const char* target, |
| 1063 const char* buf, | 1075 const char* buf, |
| 1064 unsigned int len, | 1076 unsigned int len, |
| 1065 int notify_id, | 1077 int notify_id, |
| 1066 bool popups_allowed, | 1078 bool popups_allowed, |
| 1067 bool notify_redirects) { | 1079 bool notify_redirects) { |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1326 | 1338 |
| 1327 // The plugin move sequences accumulated via DidMove are sent to the browser | 1339 // The plugin move sequences accumulated via DidMove are sent to the browser |
| 1328 // whenever the renderer paints. Force a paint here to ensure that changes | 1340 // whenever the renderer paints. Force a paint here to ensure that changes |
| 1329 // to the plugin window are propagated to the browser. | 1341 // to the plugin window are propagated to the browser. |
| 1330 container_->invalidate(); | 1342 container_->invalidate(); |
| 1331 return true; | 1343 return true; |
| 1332 } | 1344 } |
| 1333 | 1345 |
| 1334 void WebPluginImpl::TearDownPluginInstance( | 1346 void WebPluginImpl::TearDownPluginInstance( |
| 1335 WebURLLoader* loader_to_ignore) { | 1347 WebURLLoader* loader_to_ignore) { |
| 1336 // The container maintains a list of JSObjects which are related to this | 1348 // JavaScript garbage collection may cause plugin script object references to |
| 1337 // plugin. Tell the frame we're gone so that it can invalidate all of | 1349 // be retained long after the plugin is destroyed. Some plugins won't cope |
| 1338 // those sub JSObjects. | 1350 // with their objects being released after they've been destroyed, and once |
| 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. |
| 1339 if (container_) { | 1355 if (container_) { |
| 1340 container_->clearScriptObjects(); | 1356 container_->clearScriptObjects(); |
| 1341 container_->setWebLayer(NULL); | 1357 container_->setWebLayer(NULL); |
| 1342 } | 1358 } |
| 1343 | 1359 |
| 1360 // Call PluginDestroyed() first to prevent the plugin from calling us back |
| 1361 // in the middle of tearing down the render tree. |
| 1344 if (delegate_) { | 1362 if (delegate_) { |
| 1345 // Call PluginDestroyed() first to prevent the plugin from calling us back | 1363 // The plugin may call into the browser and pass script objects even during |
| 1346 // in the middle of tearing down the render tree. | 1364 // teardown, so temporarily re-enable plugin script objects. |
| 1365 DCHECK(container_); |
| 1366 container_->allowScriptObjects(); |
| 1367 |
| 1347 delegate_->PluginDestroyed(); | 1368 delegate_->PluginDestroyed(); |
| 1348 delegate_ = NULL; | 1369 delegate_ = NULL; |
| 1370 |
| 1371 // Invalidate any script objects created during teardown here, before the |
| 1372 // plugin might actually be unloaded. |
| 1373 container_->clearScriptObjects(); |
| 1349 } | 1374 } |
| 1350 | 1375 |
| 1351 // Cancel any pending requests because otherwise this deleted object will | 1376 // Cancel any pending requests because otherwise this deleted object will |
| 1352 // be called by the ResourceDispatcher. | 1377 // be called by the ResourceDispatcher. |
| 1353 std::vector<ClientInfo>::iterator client_index = clients_.begin(); | 1378 std::vector<ClientInfo>::iterator client_index = clients_.begin(); |
| 1354 while (client_index != clients_.end()) { | 1379 while (client_index != clients_.end()) { |
| 1355 ClientInfo& client_info = *client_index; | 1380 ClientInfo& client_info = *client_index; |
| 1356 | 1381 |
| 1357 if (loader_to_ignore == client_info.loader) { | 1382 if (loader_to_ignore == client_info.loader) { |
| 1358 client_index++; | 1383 client_index++; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1382 webframe_->setReferrerForRequest(*request, plugin_url_); | 1407 webframe_->setReferrerForRequest(*request, plugin_url_); |
| 1383 break; | 1408 break; |
| 1384 | 1409 |
| 1385 default: | 1410 default: |
| 1386 break; | 1411 break; |
| 1387 } | 1412 } |
| 1388 } | 1413 } |
| 1389 | 1414 |
| 1390 } // namespace npapi | 1415 } // namespace npapi |
| 1391 } // namespace webkit | 1416 } // namespace webkit |
| OLD | NEW |