Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(53)

Side by Side Diff: webkit/plugins/npapi/plugin_host.cc

Issue 6012002: Move the NPAPI files from webkit/glue/plugins to webkit/plugins/npapi and put... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « webkit/plugins/npapi/plugin_host.h ('k') | webkit/plugins/npapi/plugin_instance.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/glue/plugins/plugin_host.h" 5 #include "webkit/plugins/npapi/plugin_host.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/scoped_ptr.h" 9 #include "base/scoped_ptr.h"
10 #include "base/string_piece.h" 10 #include "base/string_piece.h"
11 #include "base/string_util.h" 11 #include "base/string_util.h"
12 #if defined(OS_MACOSX) 12 #if defined(OS_MACOSX)
13 #include "base/sys_info.h" 13 #include "base/sys_info.h"
14 #endif 14 #endif
15 #include "base/sys_string_conversions.h" 15 #include "base/sys_string_conversions.h"
16 #include "base/utf_string_conversions.h" 16 #include "base/utf_string_conversions.h"
17 #include "net/base/net_util.h" 17 #include "net/base/net_util.h"
18 #include "third_party/npapi/bindings/npapi_extensions.h" 18 #include "third_party/npapi/bindings/npapi_extensions.h"
19 #include "third_party/npapi/bindings/npruntime.h" 19 #include "third_party/npapi/bindings/npruntime.h"
20 #include "third_party/WebKit/WebKit/chromium/public/WebBindings.h" 20 #include "third_party/WebKit/WebKit/chromium/public/WebBindings.h"
21 #include "third_party/WebKit/WebKit/chromium/public/WebKit.h" 21 #include "third_party/WebKit/WebKit/chromium/public/WebKit.h"
22 #include "webkit/glue/webkit_glue.h" 22 #include "webkit/glue/webkit_glue.h"
23 #include "webkit/glue/plugins/default_plugin_shared.h" 23 #include "webkit/plugins/npapi/default_plugin_shared.h"
24 #include "webkit/glue/plugins/npapi_extension_thunk.h" 24 #include "webkit/plugins/npapi/npapi_extension_thunk.h"
25 #include "webkit/glue/plugins/plugin_instance.h" 25 #include "webkit/plugins/npapi/plugin_instance.h"
26 #include "webkit/glue/plugins/plugin_lib.h" 26 #include "webkit/plugins/npapi/plugin_lib.h"
27 #include "webkit/glue/plugins/plugin_list.h" 27 #include "webkit/plugins/npapi/plugin_list.h"
28 #include "webkit/glue/plugins/plugin_stream_url.h" 28 #include "webkit/plugins/npapi/plugin_stream_url.h"
29 #include "webkit/glue/plugins/webplugin_delegate.h" 29 #include "webkit/plugins/npapi/webplugin_delegate.h"
30 #include "webkit/glue/plugins/webplugininfo.h" 30 #include "webkit/plugins/npapi/webplugininfo.h"
31 31
32 using WebKit::WebBindings; 32 using WebKit::WebBindings;
33 33
34 namespace webkit {
35 namespace npapi {
36
34 // Finds a PluginInstance from an NPP. 37 // Finds a PluginInstance from an NPP.
35 // The caller must take a reference if needed. 38 // The caller must take a reference if needed.
36 static NPAPI::PluginInstance* FindInstance(NPP id) { 39 static PluginInstance* FindInstance(NPP id) {
37 if (id == NULL) { 40 if (id == NULL) {
38 return NULL; 41 return NULL;
39 } 42 }
40 return reinterpret_cast<NPAPI::PluginInstance*>(id->ndata); 43 return reinterpret_cast<PluginInstance*>(id->ndata);
41 } 44 }
42 45
43 #if defined(OS_MACOSX) 46 #if defined(OS_MACOSX)
44 // Returns true if the OS supports shared accelerated surfaces via IOSurface. 47 // Returns true if the OS supports shared accelerated surfaces via IOSurface.
45 // This is true on Snow Leopard and higher. 48 // This is true on Snow Leopard and higher.
46 static bool SupportsSharingAcceleratedSurfaces() { 49 static bool SupportsSharingAcceleratedSurfaces() {
47 int32 major, minor, bugfix; 50 int32 major, minor, bugfix;
48 base::SysInfo::OperatingSystemVersionNumbers(&major, &minor, &bugfix); 51 base::SysInfo::OperatingSystemVersionNumbers(&major, &minor, &bugfix);
49 return major > 10 || (major == 10 && minor > 5); 52 return major > 10 || (major == 10 && minor > 5);
50 } 53 }
51 #endif 54 #endif
52 55
53 namespace NPAPI {
54
55 scoped_refptr<PluginHost> PluginHost::singleton_; 56 scoped_refptr<PluginHost> PluginHost::singleton_;
56 57
57 PluginHost::PluginHost() { 58 PluginHost::PluginHost() {
58 InitializeHostFuncs(); 59 InitializeHostFuncs();
59 } 60 }
60 61
61 PluginHost::~PluginHost() { 62 PluginHost::~PluginHost() {
62 } 63 }
63 64
64 PluginHost *PluginHost::Singleton() { 65 PluginHost *PluginHost::Singleton() {
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 break; 271 break;
271 } 272 }
272 } 273 }
273 state = newstate; 274 state = newstate;
274 ptr++; 275 ptr++;
275 } while (!done); 276 } while (!done);
276 277
277 return !err; 278 return !err;
278 } 279 }
279 280
280 } // namespace NPAPI 281 } // namespace npapi
282 } // namespace webkit
281 283
282 extern "C" { 284 extern "C" {
283 285
286 using webkit::npapi::FindInstance;
287 using webkit::npapi::PluginHost;
288 using webkit::npapi::PluginInstance;
289 using webkit::npapi::WebPlugin;
290
284 // Allocates memory from the host's memory space. 291 // Allocates memory from the host's memory space.
285 void* NPN_MemAlloc(uint32_t size) { 292 void* NPN_MemAlloc(uint32_t size) {
286 scoped_refptr<NPAPI::PluginHost> host(NPAPI::PluginHost::Singleton()); 293 scoped_refptr<PluginHost> host(PluginHost::Singleton());
287 if (host != NULL) { 294 if (host != NULL) {
288 // Note: We must use the same allocator/deallocator 295 // Note: We must use the same allocator/deallocator
289 // that is used by the javascript library, as some of the 296 // that is used by the javascript library, as some of the
290 // JS APIs will pass memory to the plugin which the plugin 297 // JS APIs will pass memory to the plugin which the plugin
291 // will attempt to free. 298 // will attempt to free.
292 return malloc(size); 299 return malloc(size);
293 } 300 }
294 return NULL; 301 return NULL;
295 } 302 }
296 303
297 // Deallocates memory from the host's memory space 304 // Deallocates memory from the host's memory space
298 void NPN_MemFree(void* ptr) { 305 void NPN_MemFree(void* ptr) {
299 scoped_refptr<NPAPI::PluginHost> host(NPAPI::PluginHost::Singleton()); 306 scoped_refptr<PluginHost> host(PluginHost::Singleton());
300 if (host != NULL) { 307 if (host != NULL) {
301 if (ptr != NULL && ptr != reinterpret_cast<void*>(-1)) 308 if (ptr != NULL && ptr != reinterpret_cast<void*>(-1))
302 free(ptr); 309 free(ptr);
303 } 310 }
304 } 311 }
305 312
306 // Requests that the host free a specified amount of memory. 313 // Requests that the host free a specified amount of memory.
307 uint32_t NPN_MemFlush(uint32_t size) { 314 uint32_t NPN_MemFlush(uint32_t size) {
308 // This is not relevant on Windows; MAC specific 315 // This is not relevant on Windows; MAC specific
309 return size; 316 return size;
310 } 317 }
311 318
312 // This is for dynamic discovery of new plugins. 319 // This is for dynamic discovery of new plugins.
313 // Should force a re-scan of the plugins directory to load new ones. 320 // Should force a re-scan of the plugins directory to load new ones.
314 void NPN_ReloadPlugins(NPBool reload_pages) { 321 void NPN_ReloadPlugins(NPBool reload_pages) {
315 WebKit::resetPluginCache(reload_pages ? true : false); 322 WebKit::resetPluginCache(reload_pages ? true : false);
316 } 323 }
317 324
318 // Requests a range of bytes for a seekable stream. 325 // Requests a range of bytes for a seekable stream.
319 NPError NPN_RequestRead(NPStream* stream, NPByteRange* range_list) { 326 NPError NPN_RequestRead(NPStream* stream, NPByteRange* range_list) {
320 if (!stream || !range_list) 327 if (!stream || !range_list)
321 return NPERR_GENERIC_ERROR; 328 return NPERR_GENERIC_ERROR;
322 329
323 scoped_refptr<NPAPI::PluginInstance> plugin( 330 scoped_refptr<PluginInstance> plugin(
324 reinterpret_cast<NPAPI::PluginInstance*>(stream->ndata)); 331 reinterpret_cast<PluginInstance*>(stream->ndata));
325 if (!plugin.get()) 332 if (!plugin.get())
326 return NPERR_GENERIC_ERROR; 333 return NPERR_GENERIC_ERROR;
327 334
328 plugin->RequestRead(stream, range_list); 335 plugin->RequestRead(stream, range_list);
329 return NPERR_NO_ERROR; 336 return NPERR_NO_ERROR;
330 } 337 }
331 338
332 // Generic form of GetURL for common code between GetURL and GetURLNotify. 339 // Generic form of GetURL for common code between GetURL and GetURLNotify.
333 static NPError GetURLNotify(NPP id, 340 static NPError GetURLNotify(NPP id,
334 const char* url, 341 const char* url,
335 const char* target, 342 const char* target,
336 bool notify, 343 bool notify,
337 void* notify_data) { 344 void* notify_data) {
338 if (!url) 345 if (!url)
339 return NPERR_INVALID_URL; 346 return NPERR_INVALID_URL;
340 347
341 scoped_refptr<NPAPI::PluginInstance> plugin(FindInstance(id)); 348 scoped_refptr<PluginInstance> plugin(FindInstance(id));
342 if (!plugin.get()) { 349 if (!plugin.get()) {
343 return NPERR_GENERIC_ERROR; 350 return NPERR_GENERIC_ERROR;
344 } 351 }
345 352
346 plugin->RequestURL(url, "GET", target, NULL, 0, notify, notify_data); 353 plugin->RequestURL(url, "GET", target, NULL, 0, notify, notify_data);
347 return NPERR_NO_ERROR; 354 return NPERR_NO_ERROR;
348 } 355 }
349 356
350 // Requests creation of a new stream with the contents of the 357 // Requests creation of a new stream with the contents of the
351 // specified URL; gets notification of the result. 358 // specified URL; gets notification of the result.
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 const char* url, 402 const char* url,
396 const char* target, 403 const char* target,
397 uint32_t len, 404 uint32_t len,
398 const char* buf, 405 const char* buf,
399 NPBool file, 406 NPBool file,
400 bool notify, 407 bool notify,
401 void* notify_data) { 408 void* notify_data) {
402 if (!url) 409 if (!url)
403 return NPERR_INVALID_URL; 410 return NPERR_INVALID_URL;
404 411
405 scoped_refptr<NPAPI::PluginInstance> plugin(FindInstance(id)); 412 scoped_refptr<PluginInstance> plugin(FindInstance(id));
406 if (!plugin.get()) { 413 if (!plugin.get()) {
407 NOTREACHED(); 414 NOTREACHED();
408 return NPERR_GENERIC_ERROR; 415 return NPERR_GENERIC_ERROR;
409 } 416 }
410 417
411 std::string post_file_contents; 418 std::string post_file_contents;
412 419
413 if (file) { 420 if (file) {
414 // Post data to be uploaded from a file. This can be handled in two 421 // Post data to be uploaded from a file. This can be handled in two
415 // ways. 422 // ways.
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
542 NPError NPN_DestroyStream(NPP id, NPStream* stream, NPReason reason) { 549 NPError NPN_DestroyStream(NPP id, NPStream* stream, NPReason reason) {
543 // Destroys a stream (could be created by plugin or browser). 550 // Destroys a stream (could be created by plugin or browser).
544 // 551 //
545 // Reasons: 552 // Reasons:
546 // NPRES_DONE - normal completion 553 // NPRES_DONE - normal completion
547 // NPRES_USER_BREAK - user terminated 554 // NPRES_USER_BREAK - user terminated
548 // NPRES_NETWORK_ERROR - network error (all errors fit here?) 555 // NPRES_NETWORK_ERROR - network error (all errors fit here?)
549 // 556 //
550 // 557 //
551 558
552 scoped_refptr<NPAPI::PluginInstance> plugin(FindInstance(id)); 559 scoped_refptr<PluginInstance> plugin(FindInstance(id));
553 if (plugin.get() == NULL) { 560 if (plugin.get() == NULL) {
554 NOTREACHED(); 561 NOTREACHED();
555 return NPERR_GENERIC_ERROR; 562 return NPERR_GENERIC_ERROR;
556 } 563 }
557 564
558 return plugin->NPP_DestroyStream(stream, reason); 565 return plugin->NPP_DestroyStream(stream, reason);
559 } 566 }
560 567
561 const char* NPN_UserAgent(NPP id) { 568 const char* NPN_UserAgent(NPP id) {
562 #if defined(OS_WIN) 569 #if defined(OS_WIN)
563 // Flash passes in a null id during the NP_initialize call. We need to 570 // Flash passes in a null id during the NP_initialize call. We need to
564 // default to the Mozilla user agent if we don't have an NPP instance or 571 // default to the Mozilla user agent if we don't have an NPP instance or
565 // else Flash won't request windowless mode. 572 // else Flash won't request windowless mode.
566 bool use_mozilla_user_agent = true; 573 bool use_mozilla_user_agent = true;
567 if (id) { 574 if (id) {
568 scoped_refptr<NPAPI::PluginInstance> plugin = FindInstance(id); 575 scoped_refptr<PluginInstance> plugin = FindInstance(id);
569 if (plugin.get() && !plugin->use_mozilla_user_agent()) 576 if (plugin.get() && !plugin->use_mozilla_user_agent())
570 use_mozilla_user_agent = false; 577 use_mozilla_user_agent = false;
571 } 578 }
572 579
573 if (use_mozilla_user_agent) 580 if (use_mozilla_user_agent)
574 return "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9a1) " 581 return "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9a1) "
575 "Gecko/20061103 Firefox/2.0a1"; 582 "Gecko/20061103 Firefox/2.0a1";
576 #elif defined(OS_MACOSX) 583 #elif defined(OS_MACOSX)
577 // Silverlight 4 doesn't handle events correctly unless we claim to be Safari. 584 // Silverlight 4 doesn't handle events correctly unless we claim to be Safari.
578 scoped_refptr<NPAPI::PluginInstance> plugin; 585 scoped_refptr<PluginInstance> plugin;
579 if (id) 586 if (id)
580 plugin = FindInstance(id); 587 plugin = FindInstance(id);
581 if (plugin.get()) { 588 if (plugin.get()) {
582 WebPluginInfo plugin_info = plugin->plugin_lib()->plugin_info(); 589 WebPluginInfo plugin_info = plugin->plugin_lib()->plugin_info();
583 if (plugin_info.name == ASCIIToUTF16("Silverlight Plug-In") && 590 if (plugin_info.name == ASCIIToUTF16("Silverlight Plug-In") &&
584 StartsWith(plugin_info.version, ASCIIToUTF16("4."), false)) { 591 StartsWith(plugin_info.version, ASCIIToUTF16("4."), false)) {
585 return "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_4; en-us) " 592 return "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_4; en-us) "
586 "AppleWebKit/534.1+ (KHTML, like Gecko) Version/5.0 Safari/533.16"; 593 "AppleWebKit/534.1+ (KHTML, like Gecko) Version/5.0 Safari/533.16";
587 } 594 }
588 } 595 }
(...skipping 15 matching lines...) Expand all
604 611
605 // Before a windowless plugin can refresh part of its drawing area, it must 612 // Before a windowless plugin can refresh part of its drawing area, it must
606 // first invalidate it. This function causes the NPP_HandleEvent method to 613 // first invalidate it. This function causes the NPP_HandleEvent method to
607 // pass an update event or a paint message to the plug-in. After calling 614 // pass an update event or a paint message to the plug-in. After calling
608 // this method, the plug-in recieves a paint message asynchronously. 615 // this method, the plug-in recieves a paint message asynchronously.
609 616
610 // The browser redraws invalid areas of the document and any windowless 617 // The browser redraws invalid areas of the document and any windowless
611 // plug-ins at regularly timed intervals. To force a paint message, the 618 // plug-ins at regularly timed intervals. To force a paint message, the
612 // plug-in can call NPN_ForceRedraw after calling this method. 619 // plug-in can call NPN_ForceRedraw after calling this method.
613 620
614 scoped_refptr<NPAPI::PluginInstance> plugin(FindInstance(id)); 621 scoped_refptr<PluginInstance> plugin(FindInstance(id));
615 if (plugin.get() && plugin->webplugin()) { 622 if (plugin.get() && plugin->webplugin()) {
616 if (invalidRect) { 623 if (invalidRect) {
617 #if defined(OS_WIN) 624 #if defined(OS_WIN)
618 if (!plugin->windowless()) { 625 if (!plugin->windowless()) {
619 RECT rect = {0}; 626 RECT rect = {0};
620 rect.left = invalidRect->left; 627 rect.left = invalidRect->left;
621 rect.right = invalidRect->right; 628 rect.right = invalidRect->right;
622 rect.top = invalidRect->top; 629 rect.top = invalidRect->top;
623 rect.bottom = invalidRect->bottom; 630 rect.bottom = invalidRect->bottom;
624 ::InvalidateRect(plugin->window_handle(), &rect, false); 631 ::InvalidateRect(plugin->window_handle(), &rect, false);
(...skipping 12 matching lines...) Expand all
637 } 644 }
638 645
639 void NPN_InvalidateRegion(NPP id, NPRegion invalidRegion) { 646 void NPN_InvalidateRegion(NPP id, NPRegion invalidRegion) {
640 // Invalidates a specified drawing region prior to repainting 647 // Invalidates a specified drawing region prior to repainting
641 // or refreshing a window-less plugin. 648 // or refreshing a window-less plugin.
642 // 649 //
643 // Similar to NPN_InvalidateRect. 650 // Similar to NPN_InvalidateRect.
644 651
645 // TODO: this is overkill--add platform-specific region handling (at the 652 // TODO: this is overkill--add platform-specific region handling (at the
646 // very least, fetch the region's bounding box and pass it to InvalidateRect). 653 // very least, fetch the region's bounding box and pass it to InvalidateRect).
647 scoped_refptr<NPAPI::PluginInstance> plugin(FindInstance(id)); 654 scoped_refptr<PluginInstance> plugin(FindInstance(id));
648 DCHECK(plugin.get() != NULL); 655 DCHECK(plugin.get() != NULL);
649 if (plugin.get() && plugin->webplugin()) 656 if (plugin.get() && plugin->webplugin())
650 plugin->webplugin()->Invalidate(); 657 plugin->webplugin()->Invalidate();
651 } 658 }
652 659
653 void NPN_ForceRedraw(NPP id) { 660 void NPN_ForceRedraw(NPP id) {
654 // Forces repaint for a windowless plug-in. 661 // Forces repaint for a windowless plug-in.
655 // 662 //
656 // We deliberately do not implement this; we don't want plugins forcing 663 // We deliberately do not implement this; we don't want plugins forcing
657 // synchronous paints. 664 // synchronous paints.
658 } 665 }
659 666
660 NPError NPN_GetValue(NPP id, NPNVariable variable, void* value) { 667 NPError NPN_GetValue(NPP id, NPNVariable variable, void* value) {
661 // Allows the plugin to query the browser for information 668 // Allows the plugin to query the browser for information
662 // 669 //
663 // Variables: 670 // Variables:
664 // NPNVxDisplay (unix only) 671 // NPNVxDisplay (unix only)
665 // NPNVxtAppContext (unix only) 672 // NPNVxtAppContext (unix only)
666 // NPNVnetscapeWindow (win only) - Gets the native window on which the 673 // NPNVnetscapeWindow (win only) - Gets the native window on which the
667 // plug-in drawing occurs, returns HWND 674 // plug-in drawing occurs, returns HWND
668 // NPNVjavascriptEnabledBool: tells whether Javascript is enabled 675 // NPNVjavascriptEnabledBool: tells whether Javascript is enabled
669 // NPNVasdEnabledBool: tells whether SmartUpdate is enabled 676 // NPNVasdEnabledBool: tells whether SmartUpdate is enabled
670 // NPNVOfflineBool: tells whether offline-mode is enabled 677 // NPNVOfflineBool: tells whether offline-mode is enabled
671 678
672 NPError rv = NPERR_GENERIC_ERROR; 679 NPError rv = NPERR_GENERIC_ERROR;
673 680
674 switch (static_cast<int>(variable)) { 681 switch (static_cast<int>(variable)) {
675 case NPNVWindowNPObject: { 682 case NPNVWindowNPObject: {
676 scoped_refptr<NPAPI::PluginInstance> plugin(FindInstance(id)); 683 scoped_refptr<PluginInstance> plugin(FindInstance(id));
677 NPObject *np_object = plugin->webplugin()->GetWindowScriptNPObject(); 684 NPObject *np_object = plugin->webplugin()->GetWindowScriptNPObject();
678 // Return value is expected to be retained, as 685 // Return value is expected to be retained, as
679 // described here: 686 // described here:
680 // <http://www.mozilla.org/projects/plugins/npruntime.html#browseraccess> 687 // <http://www.mozilla.org/projects/plugins/npruntime.html#browseraccess>
681 if (np_object) { 688 if (np_object) {
682 WebBindings::retainObject(np_object); 689 WebBindings::retainObject(np_object);
683 void **v = (void **)value; 690 void **v = (void **)value;
684 *v = np_object; 691 *v = np_object;
685 rv = NPERR_NO_ERROR; 692 rv = NPERR_NO_ERROR;
686 } else { 693 } else {
687 NOTREACHED(); 694 NOTREACHED();
688 } 695 }
689 break; 696 break;
690 } 697 }
691 case NPNVPluginElementNPObject: { 698 case NPNVPluginElementNPObject: {
692 scoped_refptr<NPAPI::PluginInstance> plugin(FindInstance(id)); 699 scoped_refptr<PluginInstance> plugin(FindInstance(id));
693 NPObject *np_object = plugin->webplugin()->GetPluginElement(); 700 NPObject *np_object = plugin->webplugin()->GetPluginElement();
694 // Return value is expected to be retained, as 701 // Return value is expected to be retained, as
695 // described here: 702 // described here:
696 // <http://www.mozilla.org/projects/plugins/npruntime.html#browseraccess> 703 // <http://www.mozilla.org/projects/plugins/npruntime.html#browseraccess>
697 if (np_object) { 704 if (np_object) {
698 WebBindings::retainObject(np_object); 705 WebBindings::retainObject(np_object);
699 void** v = static_cast<void**>(value); 706 void** v = static_cast<void**>(value);
700 *v = np_object; 707 *v = np_object;
701 rv = NPERR_NO_ERROR; 708 rv = NPERR_NO_ERROR;
702 } else { 709 } else {
703 NOTREACHED(); 710 NOTREACHED();
704 } 711 }
705 break; 712 break;
706 } 713 }
707 #if !defined(OS_MACOSX) // OS X doesn't have windowed plugins. 714 #if !defined(OS_MACOSX) // OS X doesn't have windowed plugins.
708 case NPNVnetscapeWindow: { 715 case NPNVnetscapeWindow: {
709 scoped_refptr<NPAPI::PluginInstance> plugin = FindInstance(id); 716 scoped_refptr<PluginInstance> plugin = FindInstance(id);
710 if (!plugin.get()) { 717 if (!plugin.get()) {
711 NOTREACHED(); 718 NOTREACHED();
712 return NPERR_GENERIC_ERROR; 719 return NPERR_GENERIC_ERROR;
713 } 720 }
714 gfx::PluginWindowHandle handle = plugin->window_handle(); 721 gfx::PluginWindowHandle handle = plugin->window_handle();
715 *((void**)value) = (void*)handle; 722 *((void**)value) = (void*)handle;
716 rv = NPERR_NO_ERROR; 723 rv = NPERR_NO_ERROR;
717 break; 724 break;
718 } 725 }
719 #endif 726 #endif
(...skipping 16 matching lines...) Expand all
736 break; 743 break;
737 #endif 744 #endif
738 case NPNVSupportsWindowless: { 745 case NPNVSupportsWindowless: {
739 NPBool* supports_windowless = reinterpret_cast<NPBool*>(value); 746 NPBool* supports_windowless = reinterpret_cast<NPBool*>(value);
740 *supports_windowless = true; 747 *supports_windowless = true;
741 rv = NPERR_NO_ERROR; 748 rv = NPERR_NO_ERROR;
742 break; 749 break;
743 } 750 }
744 case NPNVprivateModeBool: { 751 case NPNVprivateModeBool: {
745 NPBool* private_mode = reinterpret_cast<NPBool*>(value); 752 NPBool* private_mode = reinterpret_cast<NPBool*>(value);
746 scoped_refptr<NPAPI::PluginInstance> plugin(FindInstance(id)); 753 scoped_refptr<PluginInstance> plugin(FindInstance(id));
747 *private_mode = plugin->webplugin()->IsOffTheRecord(); 754 *private_mode = plugin->webplugin()->IsOffTheRecord();
748 rv = NPERR_NO_ERROR; 755 rv = NPERR_NO_ERROR;
749 break; 756 break;
750 } 757 }
751 case default_plugin::kMissingPluginStatusStart + 758 case webkit::npapi::default_plugin::kMissingPluginStatusStart +
752 default_plugin::MISSING_PLUGIN_AVAILABLE: 759 webkit::npapi::default_plugin::MISSING_PLUGIN_AVAILABLE:
753 // fall through 760 // fall through
754 case default_plugin::kMissingPluginStatusStart + 761 case webkit::npapi::default_plugin::kMissingPluginStatusStart +
755 default_plugin::MISSING_PLUGIN_USER_STARTED_DOWNLOAD: { 762 webkit::npapi::default_plugin::MISSING_PLUGIN_USER_STARTED_DOWNLOAD: {
756 // This is a hack for the default plugin to send notification to 763 // This is a hack for the default plugin to send notification to
757 // renderer. Even though we check if the plugin is the default plugin, 764 // renderer. Even though we check if the plugin is the default plugin,
758 // we still need to worry about future standard change that may conflict 765 // we still need to worry about future standard change that may conflict
759 // with the variable definition, in order to avoid duplicate case clauses 766 // with the variable definition, in order to avoid duplicate case clauses
760 // in this big switch statement. 767 // in this big switch statement.
761 scoped_refptr<NPAPI::PluginInstance> plugin(FindInstance(id)); 768 scoped_refptr<PluginInstance> plugin(FindInstance(id));
762 if (plugin->plugin_lib()->plugin_info().path.value() == 769 if (plugin->plugin_lib()->plugin_info().path.value() ==
763 kDefaultPluginLibraryName) { 770 webkit::npapi::kDefaultPluginLibraryName) {
764 plugin->webplugin()->OnMissingPluginStatus( 771 plugin->webplugin()->OnMissingPluginStatus(variable -
765 variable - default_plugin::kMissingPluginStatusStart); 772 webkit::npapi::default_plugin::kMissingPluginStatusStart);
766 } 773 }
767 break; 774 break;
768 } 775 }
769 #if defined(OS_MACOSX) 776 #if defined(OS_MACOSX)
770 case NPNVpluginDrawingModel: { 777 case NPNVpluginDrawingModel: {
771 // return the drawing model that was negotiated when we initialized. 778 // return the drawing model that was negotiated when we initialized.
772 scoped_refptr<NPAPI::PluginInstance> plugin(FindInstance(id)); 779 scoped_refptr<PluginInstance> plugin(FindInstance(id));
773 *reinterpret_cast<int*>(value) = plugin->drawing_model(); 780 *reinterpret_cast<int*>(value) = plugin->drawing_model();
774 rv = NPERR_NO_ERROR; 781 rv = NPERR_NO_ERROR;
775 break; 782 break;
776 } 783 }
777 #ifndef NP_NO_QUICKDRAW 784 #ifndef NP_NO_QUICKDRAW
778 case NPNVsupportsQuickDrawBool: { 785 case NPNVsupportsQuickDrawBool: {
779 // We do not admit to supporting the QuickDraw drawing model. The logic 786 // We do not admit to supporting the QuickDraw drawing model. The logic
780 // here is that our QuickDraw plugin support is so rudimentary that we 787 // here is that our QuickDraw plugin support is so rudimentary that we
781 // only want to use it as a fallback to keep plugins from crashing: if a 788 // only want to use it as a fallback to keep plugins from crashing: if a
782 // plugin knows enough to ask, we want them to use CoreGraphics. 789 // plugin knows enough to ask, we want them to use CoreGraphics.
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
819 *supports_model = false; 826 *supports_model = false;
820 rv = NPERR_NO_ERROR; 827 rv = NPERR_NO_ERROR;
821 break; 828 break;
822 } 829 }
823 #endif // OS_MACOSX 830 #endif // OS_MACOSX
824 case NPNVPepperExtensions: 831 case NPNVPepperExtensions:
825 // Available for any plugin that attempts to get it. 832 // Available for any plugin that attempts to get it.
826 // If the plugin is not started in a Pepper implementation, it 833 // If the plugin is not started in a Pepper implementation, it
827 // will likely fail when it tries to use any of the functions 834 // will likely fail when it tries to use any of the functions
828 // attached to the extension vector. 835 // attached to the extension vector.
829 rv = NPAPI::GetPepperExtensionsFunctions(value); 836 rv = webkit::npapi::GetPepperExtensionsFunctions(value);
830 break; 837 break;
831 default: 838 default:
832 DVLOG(1) << "NPN_GetValue(" << variable << ") is not implemented yet."; 839 DVLOG(1) << "NPN_GetValue(" << variable << ") is not implemented yet.";
833 break; 840 break;
834 } 841 }
835 return rv; 842 return rv;
836 } 843 }
837 844
838 NPError NPN_SetValue(NPP id, NPPVariable variable, void* value) { 845 NPError NPN_SetValue(NPP id, NPPVariable variable, void* value) {
839 // Allows the plugin to set various modes 846 // Allows the plugin to set various modes
840 847
841 scoped_refptr<NPAPI::PluginInstance> plugin(FindInstance(id)); 848 scoped_refptr<PluginInstance> plugin(FindInstance(id));
842 switch(variable) { 849 switch(variable) {
843 case NPPVpluginWindowBool: { 850 case NPPVpluginWindowBool: {
844 // Sets windowless mode for display of the plugin 851 // Sets windowless mode for display of the plugin
845 // Note: the documentation at 852 // Note: the documentation at
846 // http://developer.mozilla.org/en/docs/NPN_SetValue is wrong. When 853 // http://developer.mozilla.org/en/docs/NPN_SetValue is wrong. When
847 // value is NULL, the mode is set to true. This is the same way Mozilla 854 // value is NULL, the mode is set to true. This is the same way Mozilla
848 // works. 855 // works.
849 plugin->set_windowless(value == 0); 856 plugin->set_windowless(value == 0);
850 return NPERR_NO_ERROR; 857 return NPERR_NO_ERROR;
851 } 858 }
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
916 return NULL; 923 return NULL;
917 } 924 }
918 925
919 void* NPN_GetJavaPeer(NPP) { 926 void* NPN_GetJavaPeer(NPP) {
920 // TODO: implement me 927 // TODO: implement me
921 DVLOG(1) << "NPN_GetJavaPeer is not implemented."; 928 DVLOG(1) << "NPN_GetJavaPeer is not implemented.";
922 return NULL; 929 return NULL;
923 } 930 }
924 931
925 void NPN_PushPopupsEnabledState(NPP id, NPBool enabled) { 932 void NPN_PushPopupsEnabledState(NPP id, NPBool enabled) {
926 scoped_refptr<NPAPI::PluginInstance> plugin(FindInstance(id)); 933 scoped_refptr<PluginInstance> plugin(FindInstance(id));
927 if (plugin) 934 if (plugin)
928 plugin->PushPopupsEnabledState(enabled ? true : false); 935 plugin->PushPopupsEnabledState(enabled ? true : false);
929 } 936 }
930 937
931 void NPN_PopPopupsEnabledState(NPP id) { 938 void NPN_PopPopupsEnabledState(NPP id) {
932 scoped_refptr<NPAPI::PluginInstance> plugin(FindInstance(id)); 939 scoped_refptr<PluginInstance> plugin(FindInstance(id));
933 if (plugin) 940 if (plugin)
934 plugin->PopPopupsEnabledState(); 941 plugin->PopPopupsEnabledState();
935 } 942 }
936 943
937 void NPN_PluginThreadAsyncCall(NPP id, 944 void NPN_PluginThreadAsyncCall(NPP id,
938 void (*func)(void*), 945 void (*func)(void*),
939 void* user_data) { 946 void* user_data) {
940 scoped_refptr<NPAPI::PluginInstance> plugin(FindInstance(id)); 947 scoped_refptr<PluginInstance> plugin(FindInstance(id));
941 if (plugin) 948 if (plugin)
942 plugin->PluginThreadAsyncCall(func, user_data); 949 plugin->PluginThreadAsyncCall(func, user_data);
943 } 950 }
944 951
945 NPError NPN_GetValueForURL(NPP id, 952 NPError NPN_GetValueForURL(NPP id,
946 NPNURLVariable variable, 953 NPNURLVariable variable,
947 const char* url, 954 const char* url,
948 char** value, 955 char** value,
949 uint32_t* len) { 956 uint32_t* len) {
950 if (!id) 957 if (!id)
951 return NPERR_INVALID_PARAM; 958 return NPERR_INVALID_PARAM;
952 959
953 if (!url || !*url || !len) 960 if (!url || !*url || !len)
954 return NPERR_INVALID_URL; 961 return NPERR_INVALID_URL;
955 962
956 *len = 0; 963 *len = 0;
957 std::string result; 964 std::string result;
958 965
959 switch (variable) { 966 switch (variable) {
960 case NPNURLVProxy: { 967 case NPNURLVProxy: {
961 result = "DIRECT"; 968 result = "DIRECT";
962 if (!webkit_glue::FindProxyForUrl(GURL((std::string(url))), &result)) 969 if (!webkit_glue::FindProxyForUrl(GURL((std::string(url))), &result))
963 return NPERR_GENERIC_ERROR; 970 return NPERR_GENERIC_ERROR;
964 971
965 break; 972 break;
966 } 973 }
967 case NPNURLVCookie: { 974 case NPNURLVCookie: {
968 scoped_refptr<NPAPI::PluginInstance> plugin(FindInstance(id)); 975 scoped_refptr<PluginInstance> plugin(FindInstance(id));
969 if (!plugin) 976 if (!plugin)
970 return NPERR_GENERIC_ERROR; 977 return NPERR_GENERIC_ERROR;
971 978
972 webkit_glue::WebPlugin* webplugin = plugin->webplugin(); 979 WebPlugin* webplugin = plugin->webplugin();
973 if (!webplugin) 980 if (!webplugin)
974 return NPERR_GENERIC_ERROR; 981 return NPERR_GENERIC_ERROR;
975 982
976 // Bypass third-party cookie blocking by using the url as the 983 // Bypass third-party cookie blocking by using the url as the
977 // first_party_for_cookies. 984 // first_party_for_cookies.
978 GURL cookies_url((std::string(url))); 985 GURL cookies_url((std::string(url)));
979 result = webplugin->GetCookies(cookies_url, cookies_url); 986 result = webplugin->GetCookies(cookies_url, cookies_url);
980 break; 987 break;
981 } 988 }
982 default: 989 default:
(...skipping 15 matching lines...) Expand all
998 const char* value, 1005 const char* value,
999 uint32_t len) { 1006 uint32_t len) {
1000 if (!id) 1007 if (!id)
1001 return NPERR_INVALID_PARAM; 1008 return NPERR_INVALID_PARAM;
1002 1009
1003 if (!url || !*url) 1010 if (!url || !*url)
1004 return NPERR_INVALID_URL; 1011 return NPERR_INVALID_URL;
1005 1012
1006 switch (variable) { 1013 switch (variable) {
1007 case NPNURLVCookie: { 1014 case NPNURLVCookie: {
1008 scoped_refptr<NPAPI::PluginInstance> plugin(FindInstance(id)); 1015 scoped_refptr<PluginInstance> plugin(FindInstance(id));
1009 if (!plugin) 1016 if (!plugin)
1010 return NPERR_GENERIC_ERROR; 1017 return NPERR_GENERIC_ERROR;
1011 1018
1012 webkit_glue::WebPlugin* webplugin = plugin->webplugin(); 1019 WebPlugin* webplugin = plugin->webplugin();
1013 if (!webplugin) 1020 if (!webplugin)
1014 return NPERR_GENERIC_ERROR; 1021 return NPERR_GENERIC_ERROR;
1015 1022
1016 std::string cookie(value, len); 1023 std::string cookie(value, len);
1017 GURL cookies_url((std::string(url))); 1024 GURL cookies_url((std::string(url)));
1018 webplugin->SetCookie(cookies_url, cookies_url, cookie); 1025 webplugin->SetCookie(cookies_url, cookies_url, cookie);
1019 return NPERR_NO_ERROR; 1026 return NPERR_NO_ERROR;
1020 } 1027 }
1021 case NPNURLVProxy: 1028 case NPNURLVProxy:
1022 // We don't support setting proxy values, fall through... 1029 // We don't support setting proxy values, fall through...
(...skipping 21 matching lines...) Expand all
1044 return NPERR_INVALID_PARAM; 1051 return NPERR_INVALID_PARAM;
1045 1052
1046 // TODO: implement me (bug 23928) 1053 // TODO: implement me (bug 23928)
1047 return NPERR_GENERIC_ERROR; 1054 return NPERR_GENERIC_ERROR;
1048 } 1055 }
1049 1056
1050 uint32_t NPN_ScheduleTimer(NPP id, 1057 uint32_t NPN_ScheduleTimer(NPP id,
1051 uint32_t interval, 1058 uint32_t interval,
1052 NPBool repeat, 1059 NPBool repeat,
1053 void (*func)(NPP id, uint32_t timer_id)) { 1060 void (*func)(NPP id, uint32_t timer_id)) {
1054 scoped_refptr<NPAPI::PluginInstance> plugin(FindInstance(id)); 1061 scoped_refptr<PluginInstance> plugin(FindInstance(id));
1055 if (!plugin) 1062 if (!plugin)
1056 return 0; 1063 return 0;
1057 1064
1058 return plugin->ScheduleTimer(interval, repeat, func); 1065 return plugin->ScheduleTimer(interval, repeat, func);
1059 } 1066 }
1060 1067
1061 void NPN_UnscheduleTimer(NPP id, uint32_t timer_id) { 1068 void NPN_UnscheduleTimer(NPP id, uint32_t timer_id) {
1062 scoped_refptr<NPAPI::PluginInstance> plugin(FindInstance(id)); 1069 scoped_refptr<PluginInstance> plugin(FindInstance(id));
1063 if (plugin) 1070 if (plugin)
1064 plugin->UnscheduleTimer(timer_id); 1071 plugin->UnscheduleTimer(timer_id);
1065 } 1072 }
1066 1073
1067 NPError NPN_PopUpContextMenu(NPP id, NPMenu* menu) { 1074 NPError NPN_PopUpContextMenu(NPP id, NPMenu* menu) {
1068 if (!menu) 1075 if (!menu)
1069 return NPERR_INVALID_PARAM; 1076 return NPERR_INVALID_PARAM;
1070 1077
1071 scoped_refptr<NPAPI::PluginInstance> plugin(FindInstance(id)); 1078 scoped_refptr<PluginInstance> plugin(FindInstance(id));
1072 if (plugin.get()) { 1079 if (plugin.get()) {
1073 return plugin->PopUpContextMenu(menu); 1080 return plugin->PopUpContextMenu(menu);
1074 } 1081 }
1075 NOTREACHED(); 1082 NOTREACHED();
1076 return NPERR_GENERIC_ERROR; 1083 return NPERR_GENERIC_ERROR;
1077 } 1084 }
1078 1085
1079 NPBool NPN_ConvertPoint(NPP id, double sourceX, double sourceY, 1086 NPBool NPN_ConvertPoint(NPP id, double sourceX, double sourceY,
1080 NPCoordinateSpace sourceSpace, 1087 NPCoordinateSpace sourceSpace,
1081 double *destX, double *destY, 1088 double *destX, double *destY,
1082 NPCoordinateSpace destSpace) { 1089 NPCoordinateSpace destSpace) {
1083 scoped_refptr<NPAPI::PluginInstance> plugin(FindInstance(id)); 1090 scoped_refptr<PluginInstance> plugin(FindInstance(id));
1084 if (plugin.get()) { 1091 if (plugin.get()) {
1085 return plugin->ConvertPoint(sourceX, sourceY, sourceSpace, 1092 return plugin->ConvertPoint(sourceX, sourceY, sourceSpace,
1086 destX, destY, destSpace); 1093 destX, destY, destSpace);
1087 } 1094 }
1088 NOTREACHED(); 1095 NOTREACHED();
1089 return false; 1096 return false;
1090 } 1097 }
1091 1098
1092 NPBool NPN_HandleEvent(NPP id, void *event, NPBool handled) { 1099 NPBool NPN_HandleEvent(NPP id, void *event, NPBool handled) {
1093 // TODO: Implement advanced key handling: http://crbug.com/46578 1100 // TODO: Implement advanced key handling: http://crbug.com/46578
1094 NOTIMPLEMENTED(); 1101 NOTIMPLEMENTED();
1095 return false; 1102 return false;
1096 } 1103 }
1097 1104
1098 NPBool NPN_UnfocusInstance(NPP id, NPFocusDirection direction) { 1105 NPBool NPN_UnfocusInstance(NPP id, NPFocusDirection direction) {
1099 // TODO: Implement advanced key handling: http://crbug.com/46578 1106 // TODO: Implement advanced key handling: http://crbug.com/46578
1100 NOTIMPLEMENTED(); 1107 NOTIMPLEMENTED();
1101 return false; 1108 return false;
1102 } 1109 }
1103 1110
1104 void NPN_URLRedirectResponse(NPP instance, void* notify_data, NPBool allow) { 1111 void NPN_URLRedirectResponse(NPP instance, void* notify_data, NPBool allow) {
1105 scoped_refptr<NPAPI::PluginInstance> plugin(FindInstance(instance)); 1112 scoped_refptr<PluginInstance> plugin(FindInstance(instance));
1106 if (plugin.get()) { 1113 if (plugin.get()) {
1107 plugin->URLRedirectResponse(!!allow, notify_data); 1114 plugin->URLRedirectResponse(!!allow, notify_data);
1108 } 1115 }
1109 } 1116 }
1110 1117
1111 } // extern "C" 1118 } // extern "C"
OLDNEW
« no previous file with comments | « webkit/plugins/npapi/plugin_host.h ('k') | webkit/plugins/npapi/plugin_instance.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698