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 "content/child/npapi/plugin_host.h" | 5 #include "content/child/npapi/plugin_host.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
| 9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 344 | 344 |
| 345 scoped_refptr<PluginInstance> plugin( | 345 scoped_refptr<PluginInstance> plugin( |
| 346 reinterpret_cast<PluginInstance*>(stream->ndata)); | 346 reinterpret_cast<PluginInstance*>(stream->ndata)); |
| 347 if (!plugin.get()) | 347 if (!plugin.get()) |
| 348 return NPERR_GENERIC_ERROR; | 348 return NPERR_GENERIC_ERROR; |
| 349 | 349 |
| 350 plugin->RequestRead(stream, range_list); | 350 plugin->RequestRead(stream, range_list); |
| 351 return NPERR_NO_ERROR; | 351 return NPERR_NO_ERROR; |
| 352 } | 352 } |
| 353 | 353 |
| 354 // Generic form of GetURL for common code between GetURL and GetURLNotify. | |
| 355 static NPError GetURLNotify(NPP id, | |
| 356 const char* url, | |
| 357 const char* target, | |
| 358 bool notify, | |
| 359 void* notify_data) { | |
| 360 if (!url) | |
| 361 return NPERR_INVALID_URL; | |
| 362 | |
| 363 scoped_refptr<PluginInstance> plugin(FindInstance(id)); | |
| 364 if (!plugin.get()) { | |
| 365 return NPERR_GENERIC_ERROR; | |
| 366 } | |
| 367 | |
| 368 plugin->RequestURL(url, "GET", target, NULL, 0, notify, notify_data); | |
| 369 return NPERR_NO_ERROR; | |
| 370 } | |
| 371 | |
| 372 // Requests creation of a new stream with the contents of the | |
| 373 // specified URL; gets notification of the result. | |
| 374 NPError NPN_GetURLNotify(NPP id, | 354 NPError NPN_GetURLNotify(NPP id, |
|
dcheng
2015/11/18 18:38:18
I feel like we should just nuke this one too.
Nate Chapin
2015/11/18 23:28:50
These functions are referenced by the _NPPluginFun
dcheng
2015/11/19 03:41:40
Oops, sorry. I posted the comment on the wrong lin
| |
| 375 const char* url, | 355 const char* url, |
| 376 const char* target, | 356 const char* target, |
| 377 void* notify_data) { | 357 void* notify_data) { |
| 378 // This is identical to NPN_GetURL, but after finishing, the | 358 return NPERR_GENERIC_ERROR; |
| 379 // browser will call NPP_URLNotify to inform the plugin that | |
| 380 // it has completed. | |
| 381 | |
| 382 // According to the NPAPI documentation, if target == _self | |
| 383 // or a parent to _self, the browser should return NPERR_INVALID_PARAM, | |
| 384 // because it can't notify the plugin once deleted. This is | |
| 385 // absolutely false; firefox doesn't do this, and Flash relies on | |
| 386 // being able to use this. | |
| 387 | |
| 388 // Also according to the NPAPI documentation, we should return | |
| 389 // NPERR_INVALID_URL if the url requested is not valid. However, | |
| 390 // this would require that we synchronously start fetching the | |
| 391 // URL. That just isn't practical. As such, there really is | |
| 392 // no way to return this error. From looking at the Firefox | |
| 393 // implementation, it doesn't look like Firefox does this either. | |
| 394 | |
| 395 return GetURLNotify(id, url, target, true, notify_data); | |
| 396 } | 359 } |
| 397 | 360 |
| 398 NPError NPN_GetURL(NPP id, const char* url, const char* target) { | 361 NPError NPN_GetURL(NPP id, const char* url, const char* target) { |
| 399 // Notes: | 362 // Notes: |
| 400 // Request from the Plugin to fetch content either for the plugin | 363 // Request from the Plugin to fetch content either for the plugin |
| 401 // or to be placed into a browser window. | 364 // or to be placed into a browser window. |
| 402 // | 365 // |
| 403 // If target == null, the browser fetches content and streams to plugin. | 366 // If target == null, the browser fetches content and streams to plugin. |
| 404 // otherwise, the browser loads content into an existing browser frame. | 367 // otherwise, the browser loads content into an existing browser frame. |
| 405 // If the target is the window/frame containing the plugin, the plugin | 368 // If the target is the window/frame containing the plugin, the plugin |
| 406 // may be destroyed. | 369 // may be destroyed. |
| 407 // If the target is _blank, a mailto: or news: url open content in a new | 370 // If the target is _blank, a mailto: or news: url open content in a new |
| 408 // browser window | 371 // browser window |
| 409 // If the target is _self, no other instance of the plugin is created. The | 372 // If the target is _self, no other instance of the plugin is created. The |
| 410 // plugin continues to operate in its own window | 373 // plugin continues to operate in its own window |
| 411 | |
| 412 return GetURLNotify(id, url, target, false, 0); | |
| 413 } | |
| 414 | |
| 415 // Generic form of PostURL for common code between PostURL and PostURLNotify. | |
| 416 static NPError PostURLNotify(NPP id, | |
| 417 const char* url, | |
| 418 const char* target, | |
| 419 uint32_t len, | |
| 420 const char* buf, | |
| 421 NPBool file, | |
| 422 bool notify, | |
| 423 void* notify_data) { | |
| 424 if (!url) | 374 if (!url) |
| 425 return NPERR_INVALID_URL; | 375 return NPERR_INVALID_URL; |
| 426 | 376 |
| 377 scoped_refptr<PluginInstance> plugin(FindInstance(id)); | |
| 378 if (!plugin.get()) { | |
| 379 return NPERR_GENERIC_ERROR; | |
| 380 } | |
| 381 | |
| 382 plugin->RequestURL(url, "GET", target, NULL, 0); | |
| 383 return NPERR_NO_ERROR; | |
| 384 } | |
| 385 | |
| 386 NPError NPN_PostURLNotify(NPP id, | |
|
dcheng
2015/11/18 18:38:18
Ditto: why not nuke?
Nate Chapin
2015/11/18 23:28:50
See above.
| |
| 387 const char* url, | |
| 388 const char* target, | |
| 389 uint32_t len, | |
| 390 const char* buf, | |
| 391 NPBool file, | |
| 392 void* notify_data) { | |
| 393 return NPERR_GENERIC_ERROR; | |
| 394 } | |
| 395 | |
| 396 NPError NPN_PostURL(NPP id, | |
| 397 const char* url, | |
| 398 const char* target, | |
| 399 uint32_t len, | |
| 400 const char* buf, | |
| 401 NPBool file) { | |
| 402 // POSTs data to an URL, either from a temp file or a buffer. | |
| 403 // If file is true, buf contains a temp file (which host will delete after | |
| 404 // completing), and len contains the length of the filename. | |
| 405 // If file is false, buf contains the data to send, and len contains the | |
| 406 // length of the buffer | |
| 407 // | |
| 408 // If target is null, | |
| 409 // server response is returned to the plugin | |
| 410 // If target is _current, _self, or _top, | |
| 411 // server response is written to the plugin window and plugin is unloaded. | |
| 412 // If target is _new or _blank, | |
| 413 // server response is written to a new browser window | |
| 414 // If target is an existing frame, | |
| 415 // server response goes to that frame. | |
| 416 // | |
| 417 // For protocols other than FTP | |
| 418 // file uploads must be line-end converted from \r\n to \n | |
| 419 | |
| 420 if (!url) | |
| 421 return NPERR_INVALID_URL; | |
| 422 | |
| 427 scoped_refptr<PluginInstance> plugin(FindInstance(id)); | 423 scoped_refptr<PluginInstance> plugin(FindInstance(id)); |
| 428 if (!plugin.get()) { | 424 if (!plugin.get()) { |
| 429 NOTREACHED(); | 425 NOTREACHED(); |
| 430 return NPERR_GENERIC_ERROR; | 426 return NPERR_GENERIC_ERROR; |
| 431 } | 427 } |
| 432 | 428 |
| 433 std::string post_file_contents; | 429 std::string post_file_contents; |
| 434 | 430 |
| 435 if (file) { | 431 if (file) { |
| 436 // Post data to be uploaded from a file. This can be handled in two | 432 // Post data to be uploaded from a file. This can be handled in two |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 488 // The post data sent by a plugin contains both headers | 484 // The post data sent by a plugin contains both headers |
| 489 // and post data. Example: | 485 // and post data. Example: |
| 490 // Content-type: text/html | 486 // Content-type: text/html |
| 491 // Content-length: 200 | 487 // Content-length: 200 |
| 492 // | 488 // |
| 493 // <200 bytes of content here> | 489 // <200 bytes of content here> |
| 494 // | 490 // |
| 495 // Unfortunately, our stream needs these broken apart, | 491 // Unfortunately, our stream needs these broken apart, |
| 496 // so we need to parse the data and set headers and data | 492 // so we need to parse the data and set headers and data |
| 497 // separately. | 493 // separately. |
| 498 plugin->RequestURL(url, "POST", target, buf, len, notify, notify_data); | 494 plugin->RequestURL(url, "POST", target, buf, len); |
| 499 return NPERR_NO_ERROR; | 495 return NPERR_NO_ERROR; |
| 500 } | 496 } |
| 501 | 497 |
| 502 NPError NPN_PostURLNotify(NPP id, | |
| 503 const char* url, | |
| 504 const char* target, | |
| 505 uint32_t len, | |
| 506 const char* buf, | |
| 507 NPBool file, | |
| 508 void* notify_data) { | |
| 509 return PostURLNotify(id, url, target, len, buf, file, true, notify_data); | |
| 510 } | |
| 511 | |
| 512 NPError NPN_PostURL(NPP id, | |
| 513 const char* url, | |
| 514 const char* target, | |
| 515 uint32_t len, | |
| 516 const char* buf, | |
| 517 NPBool file) { | |
| 518 // POSTs data to an URL, either from a temp file or a buffer. | |
| 519 // If file is true, buf contains a temp file (which host will delete after | |
| 520 // completing), and len contains the length of the filename. | |
| 521 // If file is false, buf contains the data to send, and len contains the | |
| 522 // length of the buffer | |
| 523 // | |
| 524 // If target is null, | |
| 525 // server response is returned to the plugin | |
| 526 // If target is _current, _self, or _top, | |
| 527 // server response is written to the plugin window and plugin is unloaded. | |
| 528 // If target is _new or _blank, | |
| 529 // server response is written to a new browser window | |
| 530 // If target is an existing frame, | |
| 531 // server response goes to that frame. | |
| 532 // | |
| 533 // For protocols other than FTP | |
| 534 // file uploads must be line-end converted from \r\n to \n | |
| 535 // | |
| 536 // Note: you cannot specify headers (even a blank line) in a memory buffer, | |
| 537 // use NPN_PostURLNotify | |
| 538 | |
| 539 return PostURLNotify(id, url, target, len, buf, file, false, 0); | |
| 540 } | |
| 541 | |
| 542 NPError NPN_NewStream(NPP id, | 498 NPError NPN_NewStream(NPP id, |
| 543 NPMIMEType type, | 499 NPMIMEType type, |
| 544 const char* target, | 500 const char* target, |
| 545 NPStream** stream) { | 501 NPStream** stream) { |
| 546 // Requests creation of a new data stream produced by the plugin, | 502 // Requests creation of a new data stream produced by the plugin, |
| 547 // consumed by the browser. | 503 // consumed by the browser. |
| 548 // | 504 // |
| 549 // Browser should put this stream into a window target. | 505 // Browser should put this stream into a window target. |
| 550 // | 506 // |
| 551 // TODO: implement me | 507 // TODO: implement me |
| (...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1091 return false; | 1047 return false; |
| 1092 } | 1048 } |
| 1093 | 1049 |
| 1094 NPBool NPN_UnfocusInstance(NPP id, NPFocusDirection direction) { | 1050 NPBool NPN_UnfocusInstance(NPP id, NPFocusDirection direction) { |
| 1095 // TODO: Implement advanced key handling: http://crbug.com/46578 | 1051 // TODO: Implement advanced key handling: http://crbug.com/46578 |
| 1096 NOTIMPLEMENTED(); | 1052 NOTIMPLEMENTED(); |
| 1097 return false; | 1053 return false; |
| 1098 } | 1054 } |
| 1099 | 1055 |
| 1100 void NPN_URLRedirectResponse(NPP instance, void* notify_data, NPBool allow) { | 1056 void NPN_URLRedirectResponse(NPP instance, void* notify_data, NPBool allow) { |
| 1101 scoped_refptr<PluginInstance> plugin(FindInstance(instance)); | |
| 1102 if (plugin.get()) { | |
| 1103 plugin->URLRedirectResponse(!!allow, notify_data); | |
| 1104 } | |
| 1105 } | 1057 } |
| 1106 | 1058 |
| 1107 } // extern "C" | 1059 } // extern "C" |
| OLD | NEW |