diff options
author | initial.commit@chromium.org <initial.commit@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-02 02:14:31 +0000 |
---|---|---|
committer | initial.commit@chromium.org <initial.commit@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-02 02:14:31 +0000 |
commit | 5a7bdf208c28c210b39cff63d1cf91302b02821b (patch) | |
tree | 5ff484561562f78b29d2670168a9e3b40b48dcab /ceee/common/np_browser_functions.h | |
parent | 26a54a5e0f4603c8fda2fe51789d331125993c9a (diff) | |
download | chromium_src-5a7bdf208c28c210b39cff63d1cf91302b02821b.zip chromium_src-5a7bdf208c28c210b39cff63d1cf91302b02821b.tar.gz chromium_src-5a7bdf208c28c210b39cff63d1cf91302b02821b.tar.bz2 |
Checking in the initial version of CEEE (Chrome Extensions Execution
Environment), an optional feature of Chrome Frame that acts as an
adapter layer for a subset of the Chrome Extension APIs. This enables
extensions that stick to the supported subset of APIs to work in the
context of Chrome Frame with minimal or sometimes no changes.
See http://www.chromium.org/developers/design-documents/ceee for an
overview of the design of CEEE.
TEST=unit tests (run ceee/smoke_tests.bat as an administrator on Windows)
BUG=none
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@64712 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ceee/common/np_browser_functions.h')
-rw-r--r-- | ceee/common/np_browser_functions.h | 260 |
1 files changed, 260 insertions, 0 deletions
diff --git a/ceee/common/np_browser_functions.h b/ceee/common/np_browser_functions.h new file mode 100644 index 0000000..8ab8b63 --- /dev/null +++ b/ceee/common/np_browser_functions.h @@ -0,0 +1,260 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. +#ifndef CEEE_COMMON_NP_BROWSER_FUNCTIONS_H_ +#define CEEE_COMMON_NP_BROWSER_FUNCTIONS_H_ + +#include <string> +#include "base/logging.h" +#include "third_party/npapi/bindings/nphostapi.h" + +namespace npapi { + +// Must be called prior to calling any of the browser functions below. +void InitializeBrowserFunctions(NPNetscapeFuncs* functions); +void UninitializeBrowserFunctions(); + +// Returns true iff InitializeBrowserFunctions has been called successully. +bool IsInitialized(); + +// Function stubs for functions that the host browser implements. + +NPError GetURL(NPP instance, const char* URL, const char* window); + +NPError PostURL(NPP instance, const char* URL, const char* window, uint32 len, + const char* buf, NPBool file); + +NPError RequestRead(NPStream* stream, NPByteRange* rangeList); + +NPError NewStream(NPP instance, NPMIMEType type, const char* window, + NPStream** stream); + +int32 Write(NPP instance, NPStream* stream, int32 len, void* buffer); + +NPError DestroyStream(NPP instance, NPStream* stream, NPReason reason); + +void Status(NPP instance, const char* message); + +const char* UserAgent(NPP instance); + +void* MemAlloc(uint32 size); + +void MemFree(void* ptr); + +uint32 MemFlush(uint32 size); + +void ReloadPlugins(NPBool reloadPages); + +void* GetJavaEnv(); + +void* GetJavaPeer(NPP instance); + +NPError GetURLNotify(NPP instance, const char* URL, const char* window, + void* notifyData); + +NPError PostURLNotify(NPP instance, const char* URL, const char* window, + uint32 len, const char* buf, NPBool file, + void* notifyData); + +NPError GetValue(NPP instance, NPNVariable variable, void* ret_value); + +NPError SetValue(NPP instance, NPPVariable variable, void* value); + +void InvalidateRect(NPP instance, NPRect* rect); + +void InvalidateRegion(NPP instance, NPRegion region); + +void ForceRedraw(NPP instance); + +void ReleaseVariantValue(NPVariant* variant); + +NPIdentifier GetStringIdentifier(const NPUTF8* name); + +void GetStringIdentifiers(const NPUTF8** names, int32_t nameCount, + NPIdentifier* identifiers); + +NPIdentifier GetIntIdentifier(int32_t intid); + +int32_t IntFromIdentifier(NPIdentifier identifier); + +bool IdentifierIsString(NPIdentifier identifier); + +NPUTF8* UTF8FromIdentifier(NPIdentifier identifier); + +NPObject* CreateObject(NPP, NPClass* aClass); + +NPObject* RetainObject(NPObject* obj); + +void ReleaseObject(NPObject* obj); + +bool Invoke(NPP npp, NPObject* obj, NPIdentifier methodName, + const NPVariant* args, unsigned argCount, NPVariant* result); + +bool InvokeDefault(NPP npp, NPObject* obj, const NPVariant* args, + unsigned argCount, NPVariant* result); + +bool Evaluate(NPP npp, NPObject* obj, NPString* script, NPVariant* result); + +bool GetProperty(NPP npp, NPObject* obj, NPIdentifier propertyName, + NPVariant* result); + +bool SetProperty(NPP npp, NPObject* obj, NPIdentifier propertyName, + const NPVariant* value); + +bool HasProperty(NPP npp, NPObject* npobj, NPIdentifier propertyName); + +bool HasMethod(NPP npp, NPObject* npobj, NPIdentifier methodName); + +bool RemoveProperty(NPP npp, NPObject* obj, NPIdentifier propertyName); + +void SetException(NPObject* obj, const NPUTF8* message); + +void PushPopupsEnabledState(NPP npp, NPBool enabled); + +void PopPopupsEnabledState(NPP npp); + +bool Enumerate(NPP npp, NPObject* obj, NPIdentifier** identifier, + uint32_t* count); + +void PluginThreadAsyncCall(NPP instance, + void (*func)(void*), // NOLINT + void* userData); + +bool Construct(NPP npp, NPObject* obj, const NPVariant* args, uint32_t argCount, + NPVariant* result); + +// Helper routine that wraps UTF8FromIdentifier to convert a string identifier +// to an STL string. It's not super efficient since it could possibly do two +// heap allocations (STL string has a stack based buffer for smaller strings). +// For debugging purposes it is useful. +std::string StringFromIdentifier(NPIdentifier identifier); + +} // namespace npapi + +// Simple helper class for freeing NPVariants at the end of a scope. +class ScopedNpVariant : public NPVariant { + public: + ScopedNpVariant() { + VOID_TO_NPVARIANT(*this); + } + + ~ScopedNpVariant() { + Free(); + } + + void Free() { + npapi::ReleaseVariantValue(this); + VOID_TO_NPVARIANT(*this); + } + + private: + DISALLOW_COPY_AND_ASSIGN(ScopedNpVariant); +}; + +// Simple helper class for freeing NPObjects at the end of a scope. +template <typename NpoType = NPObject> +class ScopedNpObject { + public: + ScopedNpObject() : npo_(NULL) { + } + + explicit ScopedNpObject(NpoType* npo) : npo_(npo) { + } + + ~ScopedNpObject() { + Free(); + } + + NpoType* get() const { + return npo_; + } + + operator NpoType*() const { + return npo_; + } + + NpoType* operator->() const { + return npo_; + } + + ScopedNpObject<NpoType>& operator=(NpoType* npo) { + if (npo != npo_) { + DCHECK(npo_ == NULL); + npapi::RetainObject(npo); + npo_ = npo; + } + return *this; + } + + void Free() { + if (npo_) { + npapi::ReleaseObject(npo_); + npo_ = NULL; + } + } + + NpoType** Receive() { + DCHECK(npo_ == NULL) << "Object leak. Pointer must be NULL"; + return &npo_; + } + + NpoType* Detach() { + NpoType* p = npo_; + npo_ = NULL; + return p; + } + + void Attach(NpoType* p) { + DCHECK(npo_ == NULL); + npo_ = p; + } + + NpoType* Copy() const { + if (npo_ != NULL) + npapi::RetainObject(npo_); + return npo_; + } + + bool Invoke0(NPP npp, NPIdentifier id, NPVariant* result) { + return npapi::Invoke(npp, npo_, id, NULL, 0, result); + } + bool Invoke0(NPP npp, const NPUTF8* name, NPVariant* result) { + return Invoke0(npp, npapi::GetStringIdentifier(name), result); + } + + bool Invoke1(NPP npp, NPIdentifier id, const NPVariant &arg1, + NPVariant* result) { + return npapi::Invoke(npp, npo_, id, &arg1, 1, result); + } + bool Invoke1(NPP npp, const NPUTF8* name, const NPVariant &arg1, + NPVariant* result) { + return Invoke1(npp, npapi::GetStringIdentifier(name), arg1, result); + } + bool InvokeN(NPP npp, NPIdentifier id, const NPVariant* args, unsigned argc, + NPVariant* result) { + return npapi::Invoke(npp, npo_, id, args, argc, result); + } + bool InvokeN(NPP npp, const NPUTF8* name, const NPVariant* args, + unsigned argc, NPVariant* result) { + return Invoke1(npp, npapi::GetStringIdentifier(name), args, argc, result); + } + + bool GetProperty(NPP npp, NPIdentifier id, NPVariant* result) { + return npapi::GetProperty(npp, npo_, id, result); + } + + bool GetProperty(NPP npp, const NPUTF8* name, NPVariant* result) { + return GetProperty(npp, npapi::GetStringIdentifier(name), result); + } + + private: + NpoType* npo_; + DISALLOW_COPY_AND_ASSIGN(ScopedNpObject); +}; + +// Allocates a new NPUTF8 string and assigns it to the variant. +// If memory allocation fails, the variant type will be set to NULL. +// The memory allocation is done via the npapi browser functions. +void AllocateStringVariant(const std::string& str, NPVariant* var); + +#endif // CEEE_COMMON_NP_BROWSER_FUNCTIONS_H_ |