dom/plugins/base/nsPluginNativeWindow.h

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:27589a3d7c3b
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 #ifndef _nsPluginNativeWindow_h_
7 #define _nsPluginNativeWindow_h_
8
9 #include "nscore.h"
10 #include "nsAutoPtr.h"
11 #include "nsCOMPtr.h"
12 #include "nsISupportsImpl.h"
13 #include "nsNPAPIPluginInstance.h"
14 #include "npapi.h"
15 #include "nsIWidget.h"
16
17 /**
18 * base class for native plugin window implementations
19 */
20 class nsPluginNativeWindow : public NPWindow
21 {
22 public:
23 nsPluginNativeWindow() : NPWindow() {
24 MOZ_COUNT_CTOR(nsPluginNativeWindow);
25 }
26
27 virtual ~nsPluginNativeWindow() {
28 MOZ_COUNT_DTOR(nsPluginNativeWindow);
29 }
30
31 /**
32 * !!! CAUTION !!!
33 *
34 * The base class |nsPluginWindow| is defined as a struct in nsplugindefs.h,
35 * thus it does not have a destructor of its own.
36 * One should never attempt to delete |nsPluginNativeWindow| object instance
37 * (or derivatives) using a pointer of |nsPluginWindow *| type. Should such
38 * necessity occur it must be properly casted first.
39 */
40
41 public:
42 nsresult GetPluginInstance(nsRefPtr<nsNPAPIPluginInstance> &aPluginInstance) {
43 aPluginInstance = mPluginInstance;
44 return NS_OK;
45 }
46 nsresult SetPluginInstance(nsNPAPIPluginInstance *aPluginInstance) {
47 if (mPluginInstance != aPluginInstance)
48 mPluginInstance = aPluginInstance;
49 return NS_OK;
50 }
51
52 nsresult GetPluginWidget(nsIWidget **aWidget) {
53 NS_IF_ADDREF(*aWidget = mWidget);
54 return NS_OK;
55 }
56 nsresult SetPluginWidget(nsIWidget *aWidget) {
57 mWidget = aWidget;
58 return NS_OK;
59 }
60
61 public:
62 virtual nsresult CallSetWindow(nsRefPtr<nsNPAPIPluginInstance> &aPluginInstance) {
63 // null aPluginInstance means that we want to call SetWindow(null)
64 if (aPluginInstance)
65 aPluginInstance->SetWindow(this);
66 else if (mPluginInstance)
67 mPluginInstance->SetWindow(nullptr);
68
69 SetPluginInstance(aPluginInstance);
70 return NS_OK;
71 }
72
73 protected:
74 nsRefPtr<nsNPAPIPluginInstance> mPluginInstance;
75 nsCOMPtr<nsIWidget> mWidget;
76 };
77
78 nsresult PLUG_NewPluginNativeWindow(nsPluginNativeWindow ** aPluginNativeWindow);
79 nsresult PLUG_DeletePluginNativeWindow(nsPluginNativeWindow * aPluginNativeWindow);
80
81 #endif //_nsPluginNativeWindow_h_

mercurial