Chromium Code Reviews| 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 CHECK(npp_); | |
| 290 // if (!delegate_) | |
| 291 // return NULL; | |
| 292 | |
| 293 return npp_; // delegate_->GetPluginNPP(); | |
|
jamesr
2013/05/15 22:32:15
hmm? what's up with the commented-out code here?
Wez
2013/05/15 23:14:16
Sorry, looks like this patch-set is stale. :(
| |
| 294 } | |
| 295 | |
| 283 bool WebPluginImpl::getFormValue(WebKit::WebString& value) { | 296 bool WebPluginImpl::getFormValue(WebKit::WebString& value) { |
| 284 if (!delegate_) | 297 if (!delegate_) |
| 285 return false; | 298 return false; |
| 286 base::string16 form_value; | 299 base::string16 form_value; |
| 287 if (!delegate_->GetFormValue(&form_value)) | 300 if (!delegate_->GetFormValue(&form_value)) |
| 288 return false; | 301 return false; |
| 289 value = form_value; | 302 value = form_value; |
| 290 return true; | 303 return true; |
| 291 } | 304 } |
| 292 | 305 |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 468 const WebPluginParams& params, | 481 const WebPluginParams& params, |
| 469 const base::FilePath& file_path, | 482 const base::FilePath& file_path, |
| 470 const base::WeakPtr<WebPluginPageDelegate>& page_delegate) | 483 const base::WeakPtr<WebPluginPageDelegate>& page_delegate) |
| 471 : windowless_(false), | 484 : windowless_(false), |
| 472 window_(gfx::kNullPluginWindow), | 485 window_(gfx::kNullPluginWindow), |
| 473 accepts_input_events_(false), | 486 accepts_input_events_(false), |
| 474 page_delegate_(page_delegate), | 487 page_delegate_(page_delegate), |
| 475 webframe_(webframe), | 488 webframe_(webframe), |
| 476 delegate_(NULL), | 489 delegate_(NULL), |
| 477 container_(NULL), | 490 container_(NULL), |
| 491 npp_(NULL), | |
| 478 plugin_url_(params.url), | 492 plugin_url_(params.url), |
| 479 load_manually_(params.loadManually), | 493 load_manually_(params.loadManually), |
| 480 first_geometry_update_(true), | 494 first_geometry_update_(true), |
| 481 ignore_response_error_(false), | 495 ignore_response_error_(false), |
| 482 file_path_(file_path), | 496 file_path_(file_path), |
| 483 mime_type_(UTF16ToASCII(params.mimeType)), | 497 mime_type_(UTF16ToASCII(params.mimeType)), |
| 484 weak_factory_(this) { | 498 weak_factory_(this) { |
| 485 DCHECK_EQ(params.attributeNames.size(), params.attributeValues.size()); | 499 DCHECK_EQ(params.attributeNames.size(), params.attributeValues.size()); |
| 486 StringToLowerASCII(&mime_type_); | 500 StringToLowerASCII(&mime_type_); |
| 487 | 501 |
| (...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1039 RemoveClient(i); | 1053 RemoveClient(i); |
| 1040 return; | 1054 return; |
| 1041 } | 1055 } |
| 1042 } | 1056 } |
| 1043 } | 1057 } |
| 1044 | 1058 |
| 1045 void WebPluginImpl::SetContainer(WebPluginContainer* container) { | 1059 void WebPluginImpl::SetContainer(WebPluginContainer* container) { |
| 1046 if (!container) | 1060 if (!container) |
| 1047 TearDownPluginInstance(NULL); | 1061 TearDownPluginInstance(NULL); |
| 1048 container_ = container; | 1062 container_ = container; |
| 1063 if (container_) | |
| 1064 container_->allowScriptObjects(); | |
| 1049 } | 1065 } |
| 1050 | 1066 |
| 1051 void WebPluginImpl::HandleURLRequest(const char* url, | 1067 void WebPluginImpl::HandleURLRequest(const char* url, |
| 1052 const char* method, | 1068 const char* method, |
| 1053 const char* target, | 1069 const char* target, |
| 1054 const char* buf, | 1070 const char* buf, |
| 1055 unsigned int len, | 1071 unsigned int len, |
| 1056 int notify_id, | 1072 int notify_id, |
| 1057 bool popups_allowed, | 1073 bool popups_allowed, |
| 1058 bool notify_redirects) { | 1074 bool notify_redirects) { |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1317 | 1333 |
| 1318 // The plugin move sequences accumulated via DidMove are sent to the browser | 1334 // 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 | 1335 // whenever the renderer paints. Force a paint here to ensure that changes |
| 1320 // to the plugin window are propagated to the browser. | 1336 // to the plugin window are propagated to the browser. |
| 1321 container_->invalidate(); | 1337 container_->invalidate(); |
| 1322 return true; | 1338 return true; |
| 1323 } | 1339 } |
| 1324 | 1340 |
| 1325 void WebPluginImpl::TearDownPluginInstance( | 1341 void WebPluginImpl::TearDownPluginInstance( |
| 1326 WebURLLoader* loader_to_ignore) { | 1342 WebURLLoader* loader_to_ignore) { |
| 1327 // The container maintains a list of JSObjects which are related to this | 1343 // 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 | 1344 // be retained long after the plugin is destroyed. Some plugins won't cope |
| 1329 // those sub JSObjects. | 1345 // with their objects being released after they've been destroyed, and once |
| 1346 // we've actually unloaded the plugin the object's releaseobject() code may | |
| 1347 // no longer be in memory. The container tracks the plugin's objects and lets | |
| 1348 // us invalidate them, releasing the references to them held by the JavaScript | |
| 1349 // runtime. | |
| 1330 if (container_) { | 1350 if (container_) { |
| 1331 container_->clearScriptObjects(); | 1351 container_->clearScriptObjects(); |
| 1332 container_->setWebLayer(NULL); | 1352 container_->setWebLayer(NULL); |
| 1333 } | 1353 } |
| 1334 | 1354 |
| 1355 // Call PluginDestroyed() first to prevent the plugin from calling us back | |
| 1356 // in the middle of tearing down the render tree. | |
| 1335 if (delegate_) { | 1357 if (delegate_) { |
| 1336 // Call PluginDestroyed() first to prevent the plugin from calling us back | 1358 // The plugin may call into the browser and pass script objects even during |
| 1337 // in the middle of tearing down the render tree. | 1359 // teardown, so temporarily re-enable plugin script objects. |
| 1360 DCHECK(container_); | |
| 1361 container_->allowScriptObjects(); | |
| 1362 | |
| 1338 delegate_->PluginDestroyed(); | 1363 delegate_->PluginDestroyed(); |
| 1339 delegate_ = NULL; | 1364 delegate_ = NULL; |
| 1365 | |
| 1366 // Invalidate any script objects created during teardown here, before the | |
| 1367 // plugin might actually be unloaded. | |
| 1368 container_->clearScriptObjects(); | |
| 1340 } | 1369 } |
| 1341 | 1370 |
| 1342 // Cancel any pending requests because otherwise this deleted object will | 1371 // Cancel any pending requests because otherwise this deleted object will |
| 1343 // be called by the ResourceDispatcher. | 1372 // be called by the ResourceDispatcher. |
| 1344 std::vector<ClientInfo>::iterator client_index = clients_.begin(); | 1373 std::vector<ClientInfo>::iterator client_index = clients_.begin(); |
| 1345 while (client_index != clients_.end()) { | 1374 while (client_index != clients_.end()) { |
| 1346 ClientInfo& client_info = *client_index; | 1375 ClientInfo& client_info = *client_index; |
| 1347 | 1376 |
| 1348 if (loader_to_ignore == client_info.loader) { | 1377 if (loader_to_ignore == client_info.loader) { |
| 1349 client_index++; | 1378 client_index++; |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 1373 webframe_->setReferrerForRequest(*request, plugin_url_); | 1402 webframe_->setReferrerForRequest(*request, plugin_url_); |
| 1374 break; | 1403 break; |
| 1375 | 1404 |
| 1376 default: | 1405 default: |
| 1377 break; | 1406 break; |
| 1378 } | 1407 } |
| 1379 } | 1408 } |
| 1380 | 1409 |
| 1381 } // namespace npapi | 1410 } // namespace npapi |
| 1382 } // namespace webkit | 1411 } // namespace webkit |
| OLD | NEW |