FireBreath  1.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Pages
PluginEventMac.cpp
1 /**********************************************************\
2 Original Author: Eric Herrmann
3 
4 Created: Feb 8, 2011
5 License: Dual license model; choose one of two:
6  New BSD License
7  http://www.opensource.org/licenses/bsd-license.php
8  - or -
9  GNU Lesser General Public License, version 2.1
10  http://www.gnu.org/licenses/lgpl-2.1.html
11 
12 Copyright 2011 Eric Herrmann, Firebreath development team
13 \**********************************************************/
14 
15 #include "global/config.h"
16 #include "FactoryBase.h"
17 
18 #include "PluginEventMacCocoa.h"
19 #include "PluginEventMacCarbon.h"
20 #include "PluginWindowMac.h"
21 #include "ConstructDefaultPluginWindows.h"
22 
23 #include "PluginEventMac.h"
24 
25 using namespace FB;
26 
27 FB::PluginEventMacCarbon* FB::createPluginEventMacCarbon()
28 {
29 #if FBMAC_USE_CARBON && !defined(NP_NO_CARBON)
30  return new PluginEventMacCarbon();
31 #else
32  assert(false);
33  return NULL;
34 #endif
35 }
36 
37 FB::PluginEventMacCocoa* FB::createPluginEventMacCocoa()
38 {
39 #if FBMAC_USE_COCOA
40  return new PluginEventMacCocoa();
41 #else
42  assert(false);
43  return NULL;
44 #endif
45 }
46 
47 /*
48  Apple's Safari requires NPEventModelCarbon for NPDrawingModelCoreGraphics and NPDrawingModelQuickDraw.
49  Apple's Safari requires NPEventModelCocoa for NPDrawingModelCoreGraphics, NPDrawingModelCoreAnimation, and NPDrawingModelInvalidatingCoreAnimation.
50 */
51 
52 #if FBMAC_USE_COCOA
53 static bool supports(const FB::Npapi::NpapiBrowserHostPtr &host, NPNVariable what) {
54  NPBool value = FALSE;
55  // err tells us if the browser supports model negotiation
56  NPError err = host->GetValue(what, &value);
57  return (err != NPERR_NO_ERROR) ? false : (value == FALSE) ? false : true;
58 }
59 
60 static bool set(const FB::Npapi::NpapiBrowserHostPtr &host, NPPVariable what, void* value) {
61  NPError err = host->SetValue(what, value);
62  return (err != NPERR_NO_ERROR) ? false : true;
63 }
64 #endif
65 
66 NPEventModel PluginEventMac::initPluginEventMac(const FB::Npapi::NpapiBrowserHostPtr &host, NPDrawingModel drawingModel) {
67  NPEventModel eventModel = (NPEventModel) -1;
68 #if FBMAC_USE_COCOA
69  if (
70  ((NPDrawingModelCoreAnimation == drawingModel) || (NPDrawingModelInvalidatingCoreAnimation == drawingModel) || (NPDrawingModelCoreGraphics == drawingModel))
71  && supports(host, NPNVsupportsCocoaBool)
72  && set(host, NPPVpluginEventModel, (void*)NPEventModelCocoa))
73  {
74  FBLOG_INFO("PluginCore", "NPEventModel=NPEventModelCocoa");
75  eventModel = NPEventModelCocoa;
76  } else
77 #endif
78 #if FBMAC_USE_CARBON
79 #ifndef NP_NO_CARBON
80  if (
81  (NPDrawingModelCoreGraphics == drawingModel)
82 #ifndef NP_NO_QUICKDRAW
83  || (NPDrawingModelQuickDraw == drawingModel)
84 #endif
85  )
86  {
87  FBLOG_INFO("PluginCore", "NPEventModel=NPEventModelCarbon");
88  eventModel = NPEventModelCarbon;
89  } else
90 #endif
91 #endif
92  FBLOG_INFO("PluginCore", "NPEventModel=NONE");
93  return eventModel;
94 }
95 
96 FB::PluginEventMac* PluginEventMac::createPluginEventMac(NPEventModel eventModel) {
97  PluginEventMac* rval = NULL;
98  switch (eventModel) {
99  case NPEventModelCocoa: {
100 #if FBMAC_USE_COCOA
101  rval = getFactoryInstance()->createPluginEventMacCocoa();
102 #endif
103  } break;
104 #ifndef NP_NO_CARBON
105  case NPEventModelCarbon: {
106 #if FBMAC_USE_CARBON
107  rval = getFactoryInstance()->createPluginEventMacCarbon();
108 #endif
109  } break;
110 #endif
111  }
112  return rval;
113 }
114 
Mac OS X Cocoa specific implementation of PluginEventMac.
Mac OS X Carbon specific implementation of PluginEventMac.