summaryrefslogtreecommitdiffstats
path: root/webkit/activex_shim/activex_plugin.h
blob: add15898baf801642bd1c708f0971e1c46f2b6f4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
// Copyright 2008, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
//    * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//    * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
//    * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#ifndef WEBKIT_ACTIVEX_SHIM_ACTIVEX_PLUGIN_H__
#define WEBKIT_ACTIVEX_SHIM_ACTIVEX_PLUGIN_H__

#include <string>
#include <vector>
#include "base/scoped_ptr.h"
#include "webkit/glue/plugins/nphostapi.h"
#include "webkit/activex_shim/activex_shared.h"
#include "webkit/activex_shim/dispatch_object.h"
#include "webkit/activex_shim/npn_scripting.h"
#include "webkit/activex_shim/web_activex_container.h"
#include "webkit/activex_shim/web_activex_site.h"

namespace activex_shim {

// ActiveXPlugin, a host for ActiveX control. There is one ActiveXPlugin object
// for each ActiveX control. It handles NPAPI calls from the browser side
// and is responsible for most activities of the plugin.
class ActiveXPlugin : public DispatchObject {
 public:
  explicit ActiveXPlugin(NPP instance);
  ~ActiveXPlugin();

  // NPP API Processing.
  NPError NPP_New(NPMIMEType plugin_type, int16 argc, char* argn[],
                  char* argv[], NPSavedData* saved);
  NPError NPP_SetWindow(NPWindow* window);
  NPError NPP_NewStream(NPMIMEType type, NPStream* stream,
                        NPBool seekable, uint16* stype);
  NPError NPP_DestroyStream(NPStream* stream, NPReason reason);
  int32 NPP_WriteReady(NPStream* stream);
  int32 NPP_Write(NPStream* stream, int32 offset, int32 len, void* buffer);
  void NPP_StreamAsFile(NPStream* stream, const char* fname);
  void NPP_Print(NPPrint* platformPrint);
  int16 NPP_HandleEvent(void* event);
  void NPP_URLNotify(const char* url, NPReason reason, void* notifyData);
  NPError NPP_GetValue(NPPVariable variable, void* value);
  NPError NPP_SetValue(NPNVariable variable, void* value);

  void Draw(HDC dc, RECT* lprc, RECT* lpclip);

  // Get scriptable window object from the browser.
  NPNScriptableObject GetWindow();
  // Retrieves the URL of current webpage from the browser.
  std::wstring GetCurrentURL();
  // Resolves the relative URL (could be already an absolute URL too) to return
  // full URL based on current document's URL and base.
  std::wstring ResolveURL(const std::wstring& url);
  bool windowless() { return windowless_; }
  NPP npp() { return npp_; }
  ActiveXTypes activex_type() { return activex_type_; }

 private:
  // Process parameters passed in from browser.
  void ProcessParams(int16 argc, char* argn[], char* argv[]);
  // For handling wmp mime type, we need to initialize params differently 
  // (change src to corresponding param for wmp control), and set clsid to wmp.
  void ConvertForEmbeddedWmp();

  // Overrided functions of base class: DispatchObject.
  virtual IDispatch* GetDispatch();
  virtual NPP GetNPP() { return npp_; }
  virtual bool NPObjectOwnsMe() { return false; }

  // Event handlers for windowless plugin.
  int16 HandlePaintEvent(HDC dc, NPRect* invalid_area);
  int16 HandleInputEvent(uint32 msg, uint32 wparam, uint32 lparam);

  // Related NPP instance.
  NPP npp_;
  // Position of the control relative to the browser.
  RECT rect_;
  // Initialization parameters from param tags and object tag.
  std::vector<ControlParam> params_;
  // Clsid of the activex object.
  std::wstring clsid_;
  std::wstring codebase_;
  // At this point every plugin has one container. It simplifies things.
  scoped_ptr<WebActiveXContainer> container_;
  // True if the control supports windowless and we are creating a windowless
  // plugin.
  bool windowless_;
  // Have we ever tried to activate the control.
  bool tried_activation_;
  // Whether we have successfully created the control and activated it.
  bool control_activated_;
  // Initially this is not initialized. We assign it on the first call to
  // GetWindow, then we will keep this copy.
  NPNScriptableObject window_;
  ActiveXTypes activex_type_;
  // Cache of the current url. It is used very frequently.
  std::wstring url_;

  DISALLOW_EVIL_CONSTRUCTORS(ActiveXPlugin);
};

}  // namespace activex_shim

#endif // #ifndef WEBKIT_ACTIVEX_SHIM_ACTIVEX_PLUGIN_H__