This source file includes following definitions.
- FindInstance
- SupportsCoreAnimationPlugins
- Singleton
- InitializeHostFuncs
- PatchNPNetscapeFuncs
- SetPostData
- NPN_MemAlloc
- NPN_MemFree
- NPN_MemFlush
- NPN_ReloadPlugins
- NPN_RequestRead
- GetURLNotify
- NPN_GetURLNotify
- NPN_GetURL
- PostURLNotify
- NPN_PostURLNotify
- NPN_PostURL
- NPN_NewStream
- NPN_Write
- NPN_DestroyStream
- NPN_UserAgent
- NPN_Status
- NPN_InvalidateRect
- NPN_InvalidateRegion
- NPN_ForceRedraw
- NPN_GetValue
- NPN_SetValue
- NPN_GetJavaEnv
- NPN_GetJavaPeer
- NPN_PushPopupsEnabledState
- NPN_PopPopupsEnabledState
- NPN_PluginThreadAsyncCall
- NPN_GetValueForURL
- NPN_SetValueForURL
- NPN_GetAuthenticationInfo
- NPN_ScheduleTimer
- NPN_UnscheduleTimer
- NPN_PopUpContextMenu
- NPN_ConvertPoint
- NPN_HandleEvent
- NPN_UnfocusInstance
- NPN_URLRedirectResponse
#include "content/child/npapi/plugin_host.h"
#include "base/command_line.h"
#include "base/file_util.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/strings/string_piece.h"
#include "base/strings/string_util.h"
#include "base/strings/sys_string_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
#include "content/child/npapi/plugin_instance.h"
#include "content/child/npapi/plugin_lib.h"
#include "content/child/npapi/plugin_stream_url.h"
#include "content/child/npapi/webplugin_delegate.h"
#include "content/public/common/content_client.h"
#include "content/public/common/content_switches.h"
#include "content/public/common/user_agent.h"
#include "content/public/common/webplugininfo.h"
#include "net/base/net_util.h"
#include "third_party/WebKit/public/web/WebBindings.h"
#include "third_party/WebKit/public/web/WebKit.h"
#include "third_party/npapi/bindings/npruntime.h"
#include "ui/gl/gl_implementation.h"
#include "ui/gl/gl_surface.h"
#if defined(OS_MACOSX)
#include "base/mac/mac_util.h"
#endif
using blink::WebBindings;
extern "C" {
void* NPN_GetJavaEnv();
void* NPN_GetJavaPeer(NPP);
}
namespace content {
static PluginInstance* FindInstance(NPP id) {
if (id == NULL) {
return NULL;
}
return reinterpret_cast<PluginInstance*>(id->ndata);
}
#if defined(OS_MACOSX)
static bool SupportsCoreAnimationPlugins() {
if (CommandLine::ForCurrentProcess()->HasSwitch(
switches::kDisableCoreAnimationPlugins))
return false;
static gfx::GLImplementation implementation = gfx::kGLImplementationNone;
if (implementation == gfx::kGLImplementationNone) {
DCHECK_EQ(implementation, gfx::GetGLImplementation())
<< "GL already initialized by someone else to: "
<< gfx::GetGLImplementation();
if (!gfx::GLSurface::InitializeOneOff()) {
return false;
}
implementation = gfx::GetGLImplementation();
}
return (implementation == gfx::kGLImplementationDesktopGL);
}
#endif
PluginHost::PluginHost() {
InitializeHostFuncs();
}
PluginHost::~PluginHost() {
}
PluginHost *PluginHost::Singleton() {
CR_DEFINE_STATIC_LOCAL(scoped_refptr<PluginHost>, singleton, ());
if (singleton.get() == NULL) {
singleton = new PluginHost();
}
DCHECK(singleton.get() != NULL);
return singleton.get();
}
void PluginHost::InitializeHostFuncs() {
memset(&host_funcs_, 0, sizeof(host_funcs_));
host_funcs_.size = sizeof(host_funcs_);
host_funcs_.version = (NP_VERSION_MAJOR << 8) | (NP_VERSION_MINOR);
host_funcs_.geturl = &NPN_GetURL;
host_funcs_.posturl = &NPN_PostURL;
host_funcs_.requestread = &NPN_RequestRead;
host_funcs_.newstream = &NPN_NewStream;
host_funcs_.write = &NPN_Write;
host_funcs_.destroystream = &NPN_DestroyStream;
host_funcs_.status = &NPN_Status;
host_funcs_.uagent = &NPN_UserAgent;
host_funcs_.memalloc = &NPN_MemAlloc;
host_funcs_.memfree = &NPN_MemFree;
host_funcs_.memflush = &NPN_MemFlush;
host_funcs_.reloadplugins = &NPN_ReloadPlugins;
host_funcs_.getJavaEnv = &NPN_GetJavaEnv;
host_funcs_.getJavaPeer = &NPN_GetJavaPeer;
host_funcs_.geturlnotify = &NPN_GetURLNotify;
host_funcs_.posturlnotify = &NPN_PostURLNotify;
host_funcs_.getvalue = &NPN_GetValue;
host_funcs_.setvalue = &NPN_SetValue;
host_funcs_.invalidaterect = &NPN_InvalidateRect;
host_funcs_.invalidateregion = &NPN_InvalidateRegion;
host_funcs_.forceredraw = &NPN_ForceRedraw;
host_funcs_.getstringidentifier = WebBindings::getStringIdentifier;
host_funcs_.getstringidentifiers = WebBindings::getStringIdentifiers;
host_funcs_.getintidentifier = WebBindings::getIntIdentifier;
host_funcs_.identifierisstring = WebBindings::identifierIsString;
host_funcs_.utf8fromidentifier = WebBindings::utf8FromIdentifier;
host_funcs_.intfromidentifier = WebBindings::intFromIdentifier;
host_funcs_.createobject = WebBindings::createObject;
host_funcs_.retainobject = WebBindings::retainObject;
host_funcs_.releaseobject = WebBindings::releaseObject;
host_funcs_.invoke = WebBindings::invoke;
host_funcs_.invokeDefault = WebBindings::invokeDefault;
host_funcs_.evaluate = WebBindings::evaluate;
host_funcs_.getproperty = WebBindings::getProperty;
host_funcs_.setproperty = WebBindings::setProperty;
host_funcs_.removeproperty = WebBindings::removeProperty;
host_funcs_.hasproperty = WebBindings::hasProperty;
host_funcs_.hasmethod = WebBindings::hasMethod;
host_funcs_.releasevariantvalue = WebBindings::releaseVariantValue;
host_funcs_.setexception = WebBindings::setException;
host_funcs_.pushpopupsenabledstate = NPN_PushPopupsEnabledState;
host_funcs_.poppopupsenabledstate = NPN_PopPopupsEnabledState;
host_funcs_.enumerate = WebBindings::enumerate;
host_funcs_.pluginthreadasynccall = NPN_PluginThreadAsyncCall;
host_funcs_.construct = WebBindings::construct;
host_funcs_.getvalueforurl = NPN_GetValueForURL;
host_funcs_.setvalueforurl = NPN_SetValueForURL;
host_funcs_.getauthenticationinfo = NPN_GetAuthenticationInfo;
host_funcs_.scheduletimer = NPN_ScheduleTimer;
host_funcs_.unscheduletimer = NPN_UnscheduleTimer;
host_funcs_.popupcontextmenu = NPN_PopUpContextMenu;
host_funcs_.convertpoint = NPN_ConvertPoint;
host_funcs_.handleevent = NPN_HandleEvent;
host_funcs_.unfocusinstance = NPN_UnfocusInstance;
host_funcs_.urlredirectresponse = NPN_URLRedirectResponse;
}
void PluginHost::PatchNPNetscapeFuncs(NPNetscapeFuncs* overrides) {
if (overrides->invoke)
host_funcs_.invoke = overrides->invoke;
if (overrides->invokeDefault)
host_funcs_.invokeDefault = overrides->invokeDefault;
if (overrides->evaluate)
host_funcs_.evaluate = overrides->evaluate;
if (overrides->getproperty)
host_funcs_.getproperty = overrides->getproperty;
if (overrides->setproperty)
host_funcs_.setproperty = overrides->setproperty;
if (overrides->removeproperty)
host_funcs_.removeproperty = overrides->removeproperty;
if (overrides->hasproperty)
host_funcs_.hasproperty = overrides->hasproperty;
if (overrides->hasmethod)
host_funcs_.hasmethod = overrides->hasmethod;
if (overrides->setexception)
host_funcs_.setexception = overrides->setexception;
if (overrides->enumerate)
host_funcs_.enumerate = overrides->enumerate;
}
bool PluginHost::SetPostData(const char* buf,
uint32 length,
std::vector<std::string>* names,
std::vector<std::string>* values,
std::vector<char>* body) {
enum { INPUT_COLON=0, INPUT_NEWLINE, INPUT_NULL, INPUT_OTHER };
enum { GETNAME, GETVALUE, GETDATA, DONE, ERR };
int statemachine[3][4] = { { GETVALUE, GETDATA, GETDATA, GETNAME },
{ GETVALUE, GETNAME, DONE, GETVALUE },
{ GETDATA, GETDATA, DONE, GETDATA } };
std::string name, value;
const char* ptr = static_cast<const char*>(buf);
const char* start = ptr;
int state = GETNAME;
bool done = false;
bool err = false;
do {
int input;
switch (*ptr) {
case ':' :
input = INPUT_COLON;
break;
case '\n':
input = INPUT_NEWLINE;
break;
case 0 :
input = INPUT_NULL;
break;
default :
input = INPUT_OTHER;
break;
}
int newstate = statemachine[state][input];
if (state != newstate) {
switch (newstate) {
case GETNAME:
value = std::string(start, ptr - start);
base::TrimWhitespace(value, base::TRIM_ALL, &value);
if (!name.empty() && name != "content-length") {
names->push_back(name);
values->push_back(value);
}
start = ptr + 1;
break;
case GETVALUE:
name = StringToLowerASCII(std::string(start, ptr - start));
base::TrimWhitespace(name, base::TRIM_ALL, &name);
start = ptr + 1;
break;
case GETDATA: {
if (*ptr)
start = ptr + 1;
size_t previous_size = body->size();
size_t new_body_size = length - static_cast<int>(start - buf);
body->resize(previous_size + new_body_size);
if (!body->empty())
memcpy(&body->front() + previous_size, start, new_body_size);
done = true;
break;
}
case ERR:
err = true;
done = true;
break;
}
}
state = newstate;
ptr++;
} while (!done);
return !err;
}
}
extern "C" {
using content::FindInstance;
using content::PluginHost;
using content::PluginInstance;
using content::WebPlugin;
void* NPN_MemAlloc(uint32_t size) {
return malloc(size);
}
void NPN_MemFree(void* ptr) {
if (ptr != NULL && ptr != reinterpret_cast<void*>(-1))
free(ptr);
}
uint32_t NPN_MemFlush(uint32_t size) {
return size;
}
void NPN_ReloadPlugins(NPBool reload_pages) {
blink::resetPluginCache(reload_pages ? true : false);
}
NPError NPN_RequestRead(NPStream* stream, NPByteRange* range_list) {
if (!stream || !range_list)
return NPERR_GENERIC_ERROR;
scoped_refptr<PluginInstance> plugin(
reinterpret_cast<PluginInstance*>(stream->ndata));
if (!plugin.get())
return NPERR_GENERIC_ERROR;
plugin->RequestRead(stream, range_list);
return NPERR_NO_ERROR;
}
static NPError GetURLNotify(NPP id,
const char* url,
const char* target,
bool notify,
void* notify_data) {
if (!url)
return NPERR_INVALID_URL;
scoped_refptr<PluginInstance> plugin(FindInstance(id));
if (!plugin.get()) {
return NPERR_GENERIC_ERROR;
}
plugin->RequestURL(url, "GET", target, NULL, 0, notify, notify_data);
return NPERR_NO_ERROR;
}
NPError NPN_GetURLNotify(NPP id,
const char* url,
const char* target,
void* notify_data) {
return GetURLNotify(id, url, target, true, notify_data);
}
NPError NPN_GetURL(NPP id, const char* url, const char* target) {
return GetURLNotify(id, url, target, false, 0);
}
static NPError PostURLNotify(NPP id,
const char* url,
const char* target,
uint32_t len,
const char* buf,
NPBool file,
bool notify,
void* notify_data) {
if (!url)
return NPERR_INVALID_URL;
scoped_refptr<PluginInstance> plugin(FindInstance(id));
if (!plugin.get()) {
NOTREACHED();
return NPERR_GENERIC_ERROR;
}
std::string post_file_contents;
if (file) {
if (!buf)
return NPERR_FILE_NOT_FOUND;
std::string file_path_ascii(buf);
base::FilePath file_path;
static const char kFileUrlPrefix[] = "file:";
if (StartsWithASCII(file_path_ascii, kFileUrlPrefix, false)) {
GURL file_url(file_path_ascii);
DCHECK(file_url.SchemeIsFile());
net::FileURLToFilePath(file_url, &file_path);
} else {
file_path = base::FilePath::FromUTF8Unsafe(file_path_ascii);
}
base::File::Info post_file_info;
if (!base::GetFileInfo(file_path, &post_file_info) ||
post_file_info.is_directory)
return NPERR_FILE_NOT_FOUND;
if (!base::ReadFileToString(file_path, &post_file_contents))
return NPERR_FILE_NOT_FOUND;
buf = post_file_contents.c_str();
len = post_file_contents.size();
}
plugin->RequestURL(url, "POST", target, buf, len, notify, notify_data);
return NPERR_NO_ERROR;
}
NPError NPN_PostURLNotify(NPP id,
const char* url,
const char* target,
uint32_t len,
const char* buf,
NPBool file,
void* notify_data) {
return PostURLNotify(id, url, target, len, buf, file, true, notify_data);
}
NPError NPN_PostURL(NPP id,
const char* url,
const char* target,
uint32_t len,
const char* buf,
NPBool file) {
return PostURLNotify(id, url, target, len, buf, file, false, 0);
}
NPError NPN_NewStream(NPP id,
NPMIMEType type,
const char* target,
NPStream** stream) {
DVLOG(1) << "NPN_NewStream is not implemented yet.";
return NPERR_GENERIC_ERROR;
}
int32_t NPN_Write(NPP id, NPStream* stream, int32_t len, void* buffer) {
DVLOG(1) << "NPN_Write is not implemented yet.";
return NPERR_GENERIC_ERROR;
}
NPError NPN_DestroyStream(NPP id, NPStream* stream, NPReason reason) {
scoped_refptr<PluginInstance> plugin(FindInstance(id));
if (plugin.get() == NULL) {
NOTREACHED();
return NPERR_GENERIC_ERROR;
}
return plugin->NPP_DestroyStream(stream, reason);
}
const char* NPN_UserAgent(NPP id) {
#if defined(OS_WIN)
bool use_mozilla_user_agent = true;
if (id) {
scoped_refptr<PluginInstance> plugin = FindInstance(id);
if (plugin.get() && !plugin->use_mozilla_user_agent())
use_mozilla_user_agent = false;
}
if (use_mozilla_user_agent)
return "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9a1) "
"Gecko/20061103 Firefox/2.0a1";
#endif
return content::GetContentClient()->GetUserAgent().c_str();
}
void NPN_Status(NPP id, const char* message) {
DVLOG(1) << "NPN_Status is not implemented yet.";
}
void NPN_InvalidateRect(NPP id, NPRect *invalidRect) {
scoped_refptr<PluginInstance> plugin(FindInstance(id));
if (plugin.get() && plugin->webplugin()) {
if (invalidRect) {
#if defined(OS_WIN)
if (!plugin->windowless()) {
RECT rect = {0};
rect.left = invalidRect->left;
rect.right = invalidRect->right;
rect.top = invalidRect->top;
rect.bottom = invalidRect->bottom;
::InvalidateRect(plugin->window_handle(), &rect, false);
return;
}
#endif
gfx::Rect rect(invalidRect->left,
invalidRect->top,
invalidRect->right - invalidRect->left,
invalidRect->bottom - invalidRect->top);
plugin->webplugin()->InvalidateRect(rect);
} else {
plugin->webplugin()->Invalidate();
}
}
}
void NPN_InvalidateRegion(NPP id, NPRegion invalidRegion) {
scoped_refptr<PluginInstance> plugin(FindInstance(id));
DCHECK(plugin.get() != NULL);
if (plugin.get() && plugin->webplugin())
plugin->webplugin()->Invalidate();
}
void NPN_ForceRedraw(NPP id) {
}
NPError NPN_GetValue(NPP id, NPNVariable variable, void* value) {
NPError rv = NPERR_GENERIC_ERROR;
switch (static_cast<int>(variable)) {
case NPNVWindowNPObject: {
scoped_refptr<PluginInstance> plugin(FindInstance(id));
if (!plugin.get()) {
NOTREACHED();
return NPERR_INVALID_INSTANCE_ERROR;
}
NPObject *np_object = plugin->webplugin()->GetWindowScriptNPObject();
if (np_object) {
WebBindings::retainObject(np_object);
void **v = (void **)value;
*v = np_object;
rv = NPERR_NO_ERROR;
} else {
NOTREACHED();
}
break;
}
case NPNVPluginElementNPObject: {
scoped_refptr<PluginInstance> plugin(FindInstance(id));
if (!plugin.get()) {
NOTREACHED();
return NPERR_INVALID_INSTANCE_ERROR;
}
NPObject *np_object = plugin->webplugin()->GetPluginElement();
if (np_object) {
WebBindings::retainObject(np_object);
void** v = static_cast<void**>(value);
*v = np_object;
rv = NPERR_NO_ERROR;
} else {
NOTREACHED();
}
break;
}
#if !defined(OS_MACOSX)
case NPNVnetscapeWindow: {
scoped_refptr<PluginInstance> plugin = FindInstance(id);
if (!plugin.get()) {
NOTREACHED();
return NPERR_INVALID_INSTANCE_ERROR;
}
gfx::PluginWindowHandle handle = plugin->window_handle();
*((void**)value) = (void*)handle;
rv = NPERR_NO_ERROR;
break;
}
#endif
case NPNVjavascriptEnabledBool: {
*((void**)value) = (void*)1;
rv = NPERR_NO_ERROR;
break;
}
#if defined(TOOLKIT_GTK)
case NPNVToolkit:
*reinterpret_cast<int*>(value) = NPNVGtk2;
rv = NPERR_NO_ERROR;
break;
case NPNVSupportsXEmbedBool:
*reinterpret_cast<NPBool*>(value) = true;
rv = NPERR_NO_ERROR;
break;
#endif
case NPNVSupportsWindowless: {
NPBool* supports_windowless = reinterpret_cast<NPBool*>(value);
*supports_windowless = true;
rv = NPERR_NO_ERROR;
break;
}
case NPNVprivateModeBool: {
NPBool* private_mode = reinterpret_cast<NPBool*>(value);
scoped_refptr<PluginInstance> plugin(FindInstance(id));
if (!plugin.get()) {
NOTREACHED();
return NPERR_INVALID_INSTANCE_ERROR;
}
*private_mode = plugin->webplugin()->IsOffTheRecord();
rv = NPERR_NO_ERROR;
break;
}
#if defined(OS_MACOSX)
case NPNVpluginDrawingModel: {
scoped_refptr<PluginInstance> plugin(FindInstance(id));
if (!plugin.get()) {
NOTREACHED();
return NPERR_INVALID_INSTANCE_ERROR;
}
*reinterpret_cast<int*>(value) = plugin->drawing_model();
rv = NPERR_NO_ERROR;
break;
}
case NPNVsupportsCoreGraphicsBool:
case NPNVsupportsCocoaBool: {
NPBool* supports_model = reinterpret_cast<NPBool*>(value);
*supports_model = true;
rv = NPERR_NO_ERROR;
break;
}
case NPNVsupportsInvalidatingCoreAnimationBool:
case NPNVsupportsCoreAnimationBool: {
NPBool* supports_model = reinterpret_cast<NPBool*>(value);
*supports_model = content::SupportsCoreAnimationPlugins();
rv = NPERR_NO_ERROR;
break;
}
#ifndef NP_NO_CARBON
case NPNVsupportsCarbonBool:
#endif
#ifndef NP_NO_QUICKDRAW
case NPNVsupportsQuickDrawBool:
#endif
case NPNVsupportsOpenGLBool: {
NPBool* supports_model = reinterpret_cast<NPBool*>(value);
*supports_model = false;
rv = NPERR_NO_ERROR;
break;
}
case NPNVsupportsCompositingCoreAnimationPluginsBool: {
NPBool* supports_compositing = reinterpret_cast<NPBool*>(value);
*supports_compositing = content::SupportsCoreAnimationPlugins();
rv = NPERR_NO_ERROR;
break;
}
case NPNVsupportsUpdatedCocoaTextInputBool: {
NPBool* supports_update = reinterpret_cast<NPBool*>(value);
*supports_update = true;
rv = NPERR_NO_ERROR;
break;
}
#endif
default:
DVLOG(1) << "NPN_GetValue(" << variable << ") is not implemented yet.";
break;
}
return rv;
}
NPError NPN_SetValue(NPP id, NPPVariable variable, void* value) {
scoped_refptr<PluginInstance> plugin(FindInstance(id));
if (!plugin.get()) {
NOTREACHED();
return NPERR_INVALID_INSTANCE_ERROR;
}
switch(variable) {
case NPPVpluginWindowBool: {
plugin->set_windowless(value == 0);
return NPERR_NO_ERROR;
}
case NPPVpluginTransparentBool: {
bool mode = (value != 0);
plugin->set_transparent(mode);
return NPERR_NO_ERROR;
}
case NPPVjavascriptPushCallerBool:
DVLOG(1) << "NPN_SetValue(NPPVJavascriptPushCallerBool) is not "
"implemented.";
return NPERR_GENERIC_ERROR;
case NPPVpluginKeepLibraryInMemory:
DVLOG(1) << "NPN_SetValue(NPPVpluginKeepLibraryInMemory) is not "
"implemented.";
return NPERR_GENERIC_ERROR;
#if defined(OS_MACOSX)
case NPPVpluginDrawingModel: {
intptr_t model = reinterpret_cast<intptr_t>(value);
if (model == NPDrawingModelCoreGraphics ||
((model == NPDrawingModelInvalidatingCoreAnimation ||
model == NPDrawingModelCoreAnimation) &&
content::SupportsCoreAnimationPlugins())) {
plugin->set_drawing_model(static_cast<NPDrawingModel>(model));
return NPERR_NO_ERROR;
}
return NPERR_GENERIC_ERROR;
}
case NPPVpluginEventModel: {
intptr_t model = reinterpret_cast<intptr_t>(value);
if (model == NPEventModelCocoa) {
plugin->set_event_model(static_cast<NPEventModel>(model));
return NPERR_NO_ERROR;
}
return NPERR_GENERIC_ERROR;
}
#endif
default:
DVLOG(1) << "NPN_SetValue(" << variable << ") is not implemented.";
break;
}
NOTREACHED();
return NPERR_GENERIC_ERROR;
}
void* NPN_GetJavaEnv() {
DVLOG(1) << "NPN_GetJavaEnv is not implemented.";
return NULL;
}
void* NPN_GetJavaPeer(NPP) {
DVLOG(1) << "NPN_GetJavaPeer is not implemented.";
return NULL;
}
void NPN_PushPopupsEnabledState(NPP id, NPBool enabled) {
scoped_refptr<PluginInstance> plugin(FindInstance(id));
if (plugin.get())
plugin->PushPopupsEnabledState(enabled ? true : false);
}
void NPN_PopPopupsEnabledState(NPP id) {
scoped_refptr<PluginInstance> plugin(FindInstance(id));
if (plugin.get())
plugin->PopPopupsEnabledState();
}
void NPN_PluginThreadAsyncCall(NPP id,
void (*func)(void*),
void* user_data) {
scoped_refptr<PluginInstance> plugin(FindInstance(id));
if (plugin.get())
plugin->PluginThreadAsyncCall(func, user_data);
}
NPError NPN_GetValueForURL(NPP id,
NPNURLVariable variable,
const char* url,
char** value,
uint32_t* len) {
if (!id)
return NPERR_INVALID_PARAM;
if (!url || !*url || !len)
return NPERR_INVALID_URL;
*len = 0;
std::string result;
switch (variable) {
case NPNURLVProxy: {
result = "DIRECT";
scoped_refptr<PluginInstance> plugin(FindInstance(id));
if (!plugin.get())
return NPERR_GENERIC_ERROR;
WebPlugin* webplugin = plugin->webplugin();
if (!webplugin)
return NPERR_GENERIC_ERROR;
if (!webplugin->FindProxyForUrl(GURL(std::string(url)), &result))
return NPERR_GENERIC_ERROR;
break;
}
case NPNURLVCookie: {
scoped_refptr<PluginInstance> plugin(FindInstance(id));
if (!plugin.get())
return NPERR_GENERIC_ERROR;
WebPlugin* webplugin = plugin->webplugin();
if (!webplugin)
return NPERR_GENERIC_ERROR;
GURL cookies_url((std::string(url)));
result = webplugin->GetCookies(cookies_url, cookies_url);
break;
}
default:
return NPERR_GENERIC_ERROR;
}
*value = static_cast<char*>(NPN_MemAlloc(result.length() + 1));
base::strlcpy(*value, result.c_str(), result.length() + 1);
*len = result.length();
return NPERR_NO_ERROR;
}
NPError NPN_SetValueForURL(NPP id,
NPNURLVariable variable,
const char* url,
const char* value,
uint32_t len) {
if (!id)
return NPERR_INVALID_PARAM;
if (!url || !*url)
return NPERR_INVALID_URL;
switch (variable) {
case NPNURLVCookie: {
scoped_refptr<PluginInstance> plugin(FindInstance(id));
if (!plugin.get())
return NPERR_GENERIC_ERROR;
WebPlugin* webplugin = plugin->webplugin();
if (!webplugin)
return NPERR_GENERIC_ERROR;
std::string cookie(value, len);
GURL cookies_url((std::string(url)));
webplugin->SetCookie(cookies_url, cookies_url, cookie);
return NPERR_NO_ERROR;
}
case NPNURLVProxy:
break;
default:
break;
}
return NPERR_GENERIC_ERROR;
}
NPError NPN_GetAuthenticationInfo(NPP id,
const char* protocol,
const char* host,
int32_t port,
const char* scheme,
const char* realm,
char** username,
uint32_t* ulen,
char** password,
uint32_t* plen) {
if (!id || !protocol || !host || !scheme || !realm || !username ||
!ulen || !password || !plen)
return NPERR_INVALID_PARAM;
return NPERR_GENERIC_ERROR;
}
uint32_t NPN_ScheduleTimer(NPP id,
uint32_t interval,
NPBool repeat,
void (*func)(NPP id, uint32_t timer_id)) {
scoped_refptr<PluginInstance> plugin(FindInstance(id));
if (!plugin.get())
return 0;
return plugin->ScheduleTimer(interval, repeat, func);
}
void NPN_UnscheduleTimer(NPP id, uint32_t timer_id) {
scoped_refptr<PluginInstance> plugin(FindInstance(id));
if (plugin.get())
plugin->UnscheduleTimer(timer_id);
}
NPError NPN_PopUpContextMenu(NPP id, NPMenu* menu) {
if (!menu)
return NPERR_INVALID_PARAM;
scoped_refptr<PluginInstance> plugin(FindInstance(id));
if (plugin.get()) {
return plugin->PopUpContextMenu(menu);
}
NOTREACHED();
return NPERR_GENERIC_ERROR;
}
NPBool NPN_ConvertPoint(NPP id, double sourceX, double sourceY,
NPCoordinateSpace sourceSpace,
double *destX, double *destY,
NPCoordinateSpace destSpace) {
scoped_refptr<PluginInstance> plugin(FindInstance(id));
if (plugin.get()) {
return plugin->ConvertPoint(
sourceX, sourceY, sourceSpace, destX, destY, destSpace);
}
NOTREACHED();
return false;
}
NPBool NPN_HandleEvent(NPP id, void *event, NPBool handled) {
NOTIMPLEMENTED();
return false;
}
NPBool NPN_UnfocusInstance(NPP id, NPFocusDirection direction) {
NOTIMPLEMENTED();
return false;
}
void NPN_URLRedirectResponse(NPP instance, void* notify_data, NPBool allow) {
scoped_refptr<PluginInstance> plugin(FindInstance(instance));
if (plugin.get()) {
plugin->URLRedirectResponse(!!allow, notify_data);
}
}
}