| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_FRAME_NP_BROWSER_FUNCTIONS_H_ | |
| 6 #define CHROME_FRAME_NP_BROWSER_FUNCTIONS_H_ | |
| 7 | |
| 8 #include "base/logging.h" | |
| 9 #include "third_party/npapi/bindings/npapi.h" | |
| 10 #include "third_party/npapi/bindings/nphostapi.h" | |
| 11 | |
| 12 namespace npapi { | |
| 13 | |
| 14 // Must be called prior to calling any of the browser functions below. | |
| 15 void InitializeBrowserFunctions(NPNetscapeFuncs* functions); | |
| 16 void UninitializeBrowserFunctions(); | |
| 17 | |
| 18 // Returns true iff InitializeBrowserFunctions has been called successully. | |
| 19 bool IsInitialized(); | |
| 20 | |
| 21 // Function stubs for functions that the host browser implements. | |
| 22 | |
| 23 uint8 VersionMinor(); | |
| 24 uint8 VersionMajor(); | |
| 25 | |
| 26 NPError GetURL(NPP instance, const char* URL, const char* window); | |
| 27 | |
| 28 NPError PostURL(NPP instance, const char* URL, const char* window, uint32 len, | |
| 29 const char* buf, NPBool file); | |
| 30 | |
| 31 NPError RequestRead(NPStream* stream, NPByteRange* rangeList); | |
| 32 | |
| 33 NPError NewStream(NPP instance, NPMIMEType type, const char* window, | |
| 34 NPStream** stream); | |
| 35 | |
| 36 int32 Write(NPP instance, NPStream* stream, int32 len, void* buffer); | |
| 37 | |
| 38 NPError DestroyStream(NPP instance, NPStream* stream, NPReason reason); | |
| 39 | |
| 40 void Status(NPP instance, const char* message); | |
| 41 | |
| 42 const char* UserAgent(NPP instance); | |
| 43 | |
| 44 void* MemAlloc(uint32 size); | |
| 45 | |
| 46 void MemFree(void* ptr); | |
| 47 | |
| 48 uint32 MemFlush(uint32 size); | |
| 49 | |
| 50 void ReloadPlugins(NPBool reloadPages); | |
| 51 | |
| 52 void* GetJavaEnv(); | |
| 53 | |
| 54 void* GetJavaPeer(NPP instance); | |
| 55 | |
| 56 NPError GetURLNotify(NPP instance, const char* URL, const char* window, | |
| 57 void* notifyData); | |
| 58 | |
| 59 NPError PostURLNotify(NPP instance, const char* URL, const char* window, | |
| 60 uint32 len, const char* buf, NPBool file, | |
| 61 void* notifyData); | |
| 62 | |
| 63 NPError GetValue(NPP instance, NPNVariable variable, void* ret_value); | |
| 64 | |
| 65 NPError SetValue(NPP instance, NPPVariable variable, void* value); | |
| 66 | |
| 67 void InvalidateRect(NPP instance, NPRect* rect); | |
| 68 | |
| 69 void InvalidateRegion(NPP instance, NPRegion region); | |
| 70 | |
| 71 void ForceRedraw(NPP instance); | |
| 72 | |
| 73 void ReleaseVariantValue(NPVariant* variant); | |
| 74 | |
| 75 NPIdentifier GetStringIdentifier(const NPUTF8* name); | |
| 76 | |
| 77 void GetStringIdentifiers(const NPUTF8** names, int nameCount, | |
| 78 NPIdentifier* identifiers); | |
| 79 | |
| 80 NPIdentifier GetIntIdentifier(int32_t intid); | |
| 81 | |
| 82 int32_t IntFromIdentifier(NPIdentifier identifier); | |
| 83 | |
| 84 bool IdentifierIsString(NPIdentifier identifier); | |
| 85 | |
| 86 NPUTF8* UTF8FromIdentifier(NPIdentifier identifier); | |
| 87 | |
| 88 NPObject* CreateObject(NPP, NPClass* aClass); | |
| 89 | |
| 90 NPObject* RetainObject(NPObject* obj); | |
| 91 | |
| 92 void ReleaseObject(NPObject* obj); | |
| 93 | |
| 94 bool Invoke(NPP npp, NPObject* obj, NPIdentifier methodName, | |
| 95 const NPVariant* args, unsigned argCount, NPVariant* result); | |
| 96 | |
| 97 bool InvokeDefault(NPP npp, NPObject* obj, const NPVariant* args, | |
| 98 unsigned argCount, NPVariant* result); | |
| 99 | |
| 100 bool Evaluate(NPP npp, NPObject* obj, NPString* script, NPVariant* result); | |
| 101 | |
| 102 bool GetProperty(NPP npp, NPObject* obj, NPIdentifier propertyName, | |
| 103 NPVariant* result); | |
| 104 | |
| 105 bool SetProperty(NPP npp, NPObject* obj, NPIdentifier propertyName, | |
| 106 const NPVariant* value); | |
| 107 | |
| 108 bool HasProperty(NPP npp, NPObject* npobj, NPIdentifier propertyName); | |
| 109 | |
| 110 bool HasMethod(NPP npp, NPObject* npobj, NPIdentifier methodName); | |
| 111 | |
| 112 bool RemoveProperty(NPP npp, NPObject* obj, NPIdentifier propertyName); | |
| 113 | |
| 114 void SetException(NPObject* obj, const NPUTF8* message); | |
| 115 | |
| 116 void PushPopupsEnabledState(NPP npp, NPBool enabled); | |
| 117 | |
| 118 void PopPopupsEnabledState(NPP npp); | |
| 119 | |
| 120 bool Enumerate(NPP npp, NPObject* obj, NPIdentifier** identifier, | |
| 121 uint32_t* count); | |
| 122 | |
| 123 void PluginThreadAsyncCall(NPP instance, void (*func)(void*), void* userData); | |
| 124 | |
| 125 bool Construct(NPP npp, NPObject* obj, const NPVariant* args, uint32_t argCount, | |
| 126 NPVariant* result); | |
| 127 | |
| 128 NPError GetValueForURL(NPP instance, NPNURLVariable variable, const char* url, | |
| 129 char** value, uint32* len); | |
| 130 NPError SetValueForURL(NPP instance, NPNURLVariable variable, const char* url, | |
| 131 const char* value, uint32 len); | |
| 132 NPError GetAuthenticationInfo(NPP instance, const char* protocol, | |
| 133 const char* host, int32 port, const char* scheme, | |
| 134 const char *realm, char** username, uint32* ulen, | |
| 135 char** password, uint32* plen); | |
| 136 uint32 ScheduleTimer(NPP instance, uint32 interval, NPBool repeat, | |
| 137 void (*timerFunc)(NPP npp, uint32 timerID)); | |
| 138 void UnscheduleTimer(NPP instance, uint32 timerID); | |
| 139 NPError PopUpContextMenu(NPP instance, NPMenu* menu); | |
| 140 NPBool ConvertPoint(NPP instance, double sourceX, double sourceY, | |
| 141 NPCoordinateSpace sourceSpace, double *destX, | |
| 142 double *destY, NPCoordinateSpace destSpace); | |
| 143 void URLRedirectResponse(NPP instance, void* notify_data, NPBool allow); | |
| 144 | |
| 145 // Helper routine that wraps UTF8FromIdentifier to convert a string identifier | |
| 146 // to an STL string. It's not super efficient since it could possibly do two | |
| 147 // heap allocations (STL string has a stack based buffer for smaller strings). | |
| 148 // For debugging purposes it is useful. | |
| 149 std::string StringFromIdentifier(NPIdentifier identifier); | |
| 150 | |
| 151 } // namespace npapi | |
| 152 | |
| 153 // Simple helper class for freeing NPVariants at the end of a scope. | |
| 154 class ScopedNpVariant : public NPVariant { | |
| 155 public: | |
| 156 ScopedNpVariant() { | |
| 157 VOID_TO_NPVARIANT(*this); | |
| 158 } | |
| 159 | |
| 160 ~ScopedNpVariant() { | |
| 161 Free(); | |
| 162 } | |
| 163 | |
| 164 void Free() { | |
| 165 npapi::ReleaseVariantValue(this); | |
| 166 VOID_TO_NPVARIANT(*this); | |
| 167 } | |
| 168 | |
| 169 private: | |
| 170 DISALLOW_COPY_AND_ASSIGN(ScopedNpVariant); | |
| 171 }; | |
| 172 | |
| 173 // Simple helper class for freeing NPObjects at the end of a scope. | |
| 174 template <typename NpoType = NPObject> | |
| 175 class ScopedNpObject { | |
| 176 public: | |
| 177 ScopedNpObject() : npo_(NULL) { | |
| 178 } | |
| 179 | |
| 180 explicit ScopedNpObject(NpoType* npo) : npo_(npo) { | |
| 181 } | |
| 182 | |
| 183 ~ScopedNpObject() { | |
| 184 Free(); | |
| 185 } | |
| 186 | |
| 187 NpoType* get() const { | |
| 188 return npo_; | |
| 189 } | |
| 190 | |
| 191 operator NpoType*() const { | |
| 192 return npo_; | |
| 193 } | |
| 194 | |
| 195 NpoType* operator->() const { | |
| 196 return npo_; | |
| 197 } | |
| 198 | |
| 199 ScopedNpObject<NpoType>& operator=(NpoType* npo) { | |
| 200 if (npo != npo_) { | |
| 201 DCHECK(npo_ == NULL); | |
| 202 npapi::RetainObject(npo); | |
| 203 npo_ = npo; | |
| 204 } | |
| 205 return *this; | |
| 206 } | |
| 207 | |
| 208 void Free() { | |
| 209 if (npo_) { | |
| 210 npapi::ReleaseObject(npo_); | |
| 211 npo_ = NULL; | |
| 212 } | |
| 213 } | |
| 214 | |
| 215 NpoType** Receive() { | |
| 216 DCHECK(npo_ == NULL) << "Object leak. Pointer must be NULL"; | |
| 217 return &npo_; | |
| 218 } | |
| 219 | |
| 220 NpoType* Detach() { | |
| 221 NpoType* p = npo_; | |
| 222 npo_ = NULL; | |
| 223 return p; | |
| 224 } | |
| 225 | |
| 226 void Attach(NpoType* p) { | |
| 227 DCHECK(npo_ == NULL); | |
| 228 npo_ = p; | |
| 229 } | |
| 230 | |
| 231 NpoType* Copy() const { | |
| 232 if (npo_ != NULL) | |
| 233 npapi::RetainObject(npo_); | |
| 234 return npo_; | |
| 235 } | |
| 236 | |
| 237 bool Invoke0(NPP npp, NPIdentifier id, NPVariant* result) { | |
| 238 return npapi::Invoke(npp, npo_, id, NULL, 0, result); | |
| 239 } | |
| 240 bool Invoke0(NPP npp, const NPUTF8* name, NPVariant* result) { | |
| 241 return Invoke0(npp, npapi::GetStringIdentifier(name), result); | |
| 242 } | |
| 243 | |
| 244 bool Invoke1(NPP npp, NPIdentifier id, const NPVariant &arg1, | |
| 245 NPVariant* result) { | |
| 246 return npapi::Invoke(npp, npo_, id, &arg1, 1, result); | |
| 247 } | |
| 248 bool Invoke1(NPP npp, const NPUTF8* name, const NPVariant &arg1, | |
| 249 NPVariant* result) { | |
| 250 return Invoke1(npp, npapi::GetStringIdentifier(name), arg1, result); | |
| 251 } | |
| 252 bool InvokeN(NPP npp, NPIdentifier id, const NPVariant* args, unsigned argc, | |
| 253 NPVariant* result) { | |
| 254 return npapi::Invoke(npp, npo_, id, args, argc, result); | |
| 255 } | |
| 256 bool InvokeN(NPP npp, const NPUTF8* name, const NPVariant* args, | |
| 257 unsigned argc, NPVariant* result) { | |
| 258 return Invoke1(npp, npapi::GetStringIdentifier(name), args, argc, result); | |
| 259 } | |
| 260 | |
| 261 bool GetProperty(NPP npp, NPIdentifier id, NPVariant* result) { | |
| 262 return npapi::GetProperty(npp, npo_, id, result); | |
| 263 } | |
| 264 | |
| 265 bool GetProperty(NPP npp, const NPUTF8* name, NPVariant* result) { | |
| 266 return GetProperty(npp, npapi::GetStringIdentifier(name), result); | |
| 267 } | |
| 268 | |
| 269 private: | |
| 270 NpoType* npo_; | |
| 271 DISALLOW_COPY_AND_ASSIGN(ScopedNpObject); | |
| 272 }; | |
| 273 | |
| 274 // Allocates a new NPUTF8 string and assigns it to the variant. | |
| 275 // If memory allocation fails, the variant type will be set to NULL. | |
| 276 // The memory allocation is done via the npapi browser functions. | |
| 277 void AllocateStringVariant(const std::string& str, NPVariant* var); | |
| 278 | |
| 279 // Returns true if the host browser supports the NPAPI redirect notification | |
| 280 // spec. https://wiki.mozilla.org/NPAPI:HTTPRedirectHandling | |
| 281 bool BrowserSupportsRedirectNotification(); | |
| 282 | |
| 283 #endif // CHROME_FRAME_NP_BROWSER_FUNCTIONS_H_ | |
| OLD | NEW |