From a3929294e9176abc6085d87cb2c6f8f8417b58f3 Mon Sep 17 00:00:00 2001 From: "jorlow@chromium.org" Date: Thu, 30 Jul 2009 00:35:33 +0000 Subject: Continue eliminating direct NPN_ function calls that go from Chromium code to WebKit code. The long-term goal is to be able to link WebKit as a DLL. TEST=none BUG=none Review URL: http://codereview.chromium.org/160310 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@22031 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/common/plugin_messages.h | 8 ++++--- chrome/plugin/npobject_proxy.cc | 4 +++- chrome/plugin/npobject_stub.cc | 37 ++++++++++++++++------------- chrome/plugin/webplugin_delegate_stub.cc | 4 +++- chrome/plugin/webplugin_proxy.cc | 7 ++++-- chrome/renderer/external_host_bindings.cc | 30 +++++++++++++---------- chrome/renderer/webplugin_delegate_proxy.cc | 6 ++--- 7 files changed, 56 insertions(+), 40 deletions(-) (limited to 'chrome') diff --git a/chrome/common/plugin_messages.h b/chrome/common/plugin_messages.h index dd1ee18..5c35544 100644 --- a/chrome/common/plugin_messages.h +++ b/chrome/common/plugin_messages.h @@ -21,6 +21,7 @@ #include "googleurl/src/gurl.h" #include "ipc/ipc_message_utils.h" #include "third_party/npapi/bindings/npapi.h" +#include "webkit/api/public/WebBindings.h" #include "webkit/api/public/WebInputEvent.h" #include "webkit/glue/npruntime_util.h" @@ -321,12 +322,13 @@ struct ParamTraits { return webkit_glue::DeserializeNPIdentifier(*m, iter, &r->identifier); } static void Log(const param_type& p, std::wstring* l) { - if (NPN_IdentifierIsString(p.identifier)) { - NPUTF8* str = NPN_UTF8FromIdentifier(p.identifier); + if (WebKit::WebBindings::identifierIsString(p.identifier)) { + NPUTF8* str = WebKit::WebBindings::utf8FromIdentifier(p.identifier); l->append(UTF8ToWide(str)); NPN_MemFree(str); } else { - l->append(IntToWString(NPN_IntFromIdentifier(p.identifier))); + l->append(IntToWString( + WebKit::WebBindings::intFromIdentifier(p.identifier))); } } }; diff --git a/chrome/plugin/npobject_proxy.cc b/chrome/plugin/npobject_proxy.cc index bc99ffe..f224cdb 100644 --- a/chrome/plugin/npobject_proxy.cc +++ b/chrome/plugin/npobject_proxy.cc @@ -8,9 +8,11 @@ #include "chrome/common/plugin_messages.h" #include "chrome/plugin/npobject_util.h" #include "chrome/plugin/plugin_channel_base.h" +#include "webkit/api/public/WebBindings.h" #include "webkit/glue/webkit_glue.h" #include "webkit/glue/plugins/plugin_instance.h" +using WebKit::WebBindings; struct NPObjectWrapper { NPObject object; @@ -73,7 +75,7 @@ NPObject* NPObjectProxy::Create(PluginChannelBase* channel, base::WaitableEvent* modal_dialog_event, const GURL& page_url) { NPObjectWrapper* obj = reinterpret_cast( - NPN_CreateObject(0, &npclass_proxy_)); + WebBindings::createObject(0, &npclass_proxy_)); obj->proxy = new NPObjectProxy( channel, route_id, npobject_ptr, modal_dialog_event, page_url); diff --git a/chrome/plugin/npobject_stub.cc b/chrome/plugin/npobject_stub.cc index 4345d37..7287f4c 100644 --- a/chrome/plugin/npobject_stub.cc +++ b/chrome/plugin/npobject_stub.cc @@ -11,6 +11,9 @@ #include "chrome/renderer/webplugin_delegate_proxy.h" #include "third_party/npapi/bindings/npapi.h" #include "third_party/npapi/bindings/npruntime.h" +#include "webkit/api/public/WebBindings.h" + +using WebKit::WebBindings; NPObjectStub::NPObjectStub( NPObject* npobject, @@ -28,7 +31,7 @@ NPObjectStub::NPObjectStub( channel_->AddRoute(route_id, this, true); // We retain the object just as PluginHost does if everything was in-process. - NPN_RetainObject(npobject_); + WebBindings::retainObject(npobject_); } NPObjectStub::~NPObjectStub() { @@ -37,7 +40,7 @@ NPObjectStub::~NPObjectStub() { channel_->RemoveRoute(route_id_); if (npobject_ && valid_) - NPN_ReleaseObject(npobject_); + WebBindings::releaseObject(npobject_); } bool NPObjectStub::Send(IPC::Message* msg) { @@ -103,7 +106,7 @@ void NPObjectStub::OnHasMethod(const NPIdentifier_Param& name, *result = false; } } else { - *result = NPN_HasMethod(0, npobject_, id); + *result = WebBindings::hasMethod(0, npobject_, id); } } @@ -135,7 +138,7 @@ void NPObjectStub::OnInvoke(bool is_default, return_value = false; } } else { - return_value = NPN_InvokeDefault( + return_value = WebBindings::invokeDefault( 0, npobject_, args_var, arg_count, &result_var); } } else { @@ -148,13 +151,13 @@ void NPObjectStub::OnInvoke(bool is_default, return_value = false; } } else { - return_value = NPN_Invoke( + return_value = WebBindings::invoke( 0, npobject_, id, args_var, arg_count, &result_var); } } for (int i = 0; i < arg_count; ++i) - NPN_ReleaseVariantValue(&(args_var[i])); + WebBindings::releaseVariantValue(&(args_var[i])); delete[] args_var; @@ -175,7 +178,7 @@ void NPObjectStub::OnHasProperty(const NPIdentifier_Param& name, *result = false; } } else { - *result = NPN_HasProperty(0, npobject_, id); + *result = WebBindings::hasProperty(0, npobject_, id); } } @@ -193,7 +196,7 @@ void NPObjectStub::OnGetProperty(const NPIdentifier_Param& name, *result = false; } } else { - *result = NPN_GetProperty(0, npobject_, id, &result_var); + *result = WebBindings::getProperty(0, npobject_, id, &result_var); } CreateNPVariantParam( @@ -217,10 +220,10 @@ void NPObjectStub::OnSetProperty(const NPIdentifier_Param& name, *result = false; } } else { - *result = NPN_SetProperty(0, npobject_, id, &property_var); + *result = WebBindings::setProperty(0, npobject_, id, &property_var); } - NPN_ReleaseVariantValue(&property_var); + WebBindings::releaseVariantValue(&property_var); } void NPObjectStub::OnRemoveProperty(const NPIdentifier_Param& name, @@ -233,7 +236,7 @@ void NPObjectStub::OnRemoveProperty(const NPIdentifier_Param& name, *result = false; } } else { - *result = NPN_RemoveProperty(0, npobject_, id); + *result = WebBindings::removeProperty(0, npobject_, id); } } @@ -254,7 +257,7 @@ void NPObjectStub::OnEnumeration(std::vector* value, NPIdentifier* value_np = NULL; unsigned int count = 0; if (!IsPluginProcess()) { - *result = NPN_Enumerate(0, npobject_, &value_np, &count); + *result = WebBindings::enumerate(0, npobject_, &value_np, &count); } else { if (!npobject_->_class->enumerate) { *result = false; @@ -300,12 +303,12 @@ void NPObjectStub::OnConstruct(const std::vector& args, return_value = false; } } else { - return_value = NPN_Construct( + return_value = WebBindings::construct( 0, npobject_, args_var, arg_count, &result_var); } for (int i = 0; i < arg_count; ++i) - NPN_ReleaseVariantValue(&(args_var[i])); + WebBindings::releaseVariantValue(&(args_var[i])); delete[] args_var; @@ -335,8 +338,8 @@ void NPObjectStub::OnEvaluate(const std::string& script, script_string.UTF8Characters = script.c_str(); script_string.UTF8Length = static_cast(script.length()); - bool return_value = NPN_EvaluateHelper(0, popups_allowed, npobject_, - &script_string, &result_var); + bool return_value = WebBindings::evaluateHelper(0, popups_allowed, npobject_, + &script_string, &result_var); NPVariant_Param result_param; CreateNPVariantParam( @@ -352,5 +355,5 @@ void NPObjectStub::OnSetException(const std::string& message) { return; } - NPN_SetException(npobject_, message.c_str()); + WebBindings::setException(npobject_, message.c_str()); } diff --git a/chrome/plugin/webplugin_delegate_stub.cc b/chrome/plugin/webplugin_delegate_stub.cc index a8a42b0..277ff91 100644 --- a/chrome/plugin/webplugin_delegate_stub.cc +++ b/chrome/plugin/webplugin_delegate_stub.cc @@ -18,10 +18,12 @@ #include "third_party/npapi/bindings/npapi.h" #include "third_party/npapi/bindings/npruntime.h" #include "skia/ext/platform_device.h" +#include "webkit/api/public/WebBindings.h" #include "webkit/api/public/WebCursorInfo.h" #include "webkit/glue/webcursor.h" #include "webkit/glue/webplugin_delegate.h" +using WebKit::WebBindings; using WebKit::WebCursorInfo; class FinishDestructionTask : public Task { @@ -296,7 +298,7 @@ void WebPluginDelegateStub::OnGetPluginScriptableObject(int* route_id, page_url_); // Release ref added by GetPluginScriptableObject (our stub holds its own). - NPN_ReleaseObject(object); + WebBindings::releaseObject(object); } void WebPluginDelegateStub::OnSendJavaScriptStream(const std::string& url, diff --git a/chrome/plugin/webplugin_proxy.cc b/chrome/plugin/webplugin_proxy.cc index 5b150581..8a27a57 100644 --- a/chrome/plugin/webplugin_proxy.cc +++ b/chrome/plugin/webplugin_proxy.cc @@ -23,12 +23,15 @@ #include "chrome/plugin/plugin_thread.h" #include "chrome/plugin/webplugin_delegate_stub.h" #include "skia/ext/platform_device.h" +#include "webkit/api/public/WebBindings.h" #include "webkit/glue/webplugin_delegate.h" #if defined(OS_WIN) #include "base/gfx/gdi_util.h" #endif +using WebKit::WebBindings; + typedef std::map ContextMap; static ContextMap& GetContextMap() { return *Singleton::get(); @@ -153,7 +156,7 @@ void WebPluginProxy::InvalidateRect(const gfx::Rect& rect) { NPObject* WebPluginProxy::GetWindowScriptNPObject() { if (window_npobject_) - return NPN_RetainObject(window_npobject_); + return WebBindings::retainObject(window_npobject_); int npobject_route_id = channel_->GenerateRouteID(); bool success = false; @@ -172,7 +175,7 @@ NPObject* WebPluginProxy::GetWindowScriptNPObject() { NPObject* WebPluginProxy::GetPluginElement() { if (plugin_element_) - return NPN_RetainObject(plugin_element_); + return WebBindings::retainObject(plugin_element_); int npobject_route_id = channel_->GenerateRouteID(); bool success = false; diff --git a/chrome/renderer/external_host_bindings.cc b/chrome/renderer/external_host_bindings.cc index 108ee34..7aaf139 100644 --- a/chrome/renderer/external_host_bindings.cc +++ b/chrome/renderer/external_host_bindings.cc @@ -6,8 +6,11 @@ #include "base/values.h" #include "chrome/common/render_messages.h" +#include "webkit/api/public/WebBindings.h" #include "webkit/glue/webframe.h" +using WebKit::WebBindings; + ExternalHostBindings::ExternalHostBindings() : frame_(NULL) { BindMethod("postMessage", &ExternalHostBindings::postMessage); BindProperty("onmessage", &on_message_handler_); @@ -96,7 +99,7 @@ bool ExternalHostBindings::ForwardMessageFromExternalHost( NOTREACHED() << "CreateMessageEvent failed"; } else { NPIdentifier init_message_event = - NPN_GetStringIdentifier("initMessageEvent"); + WebBindings::getStringIdentifier("initMessageEvent"); NPVariant init_args[8]; STRINGN_TO_NPVARIANT("message", sizeof("message") - 1, init_args[0]); // type @@ -112,22 +115,23 @@ bool ExternalHostBindings::ForwardMessageFromExternalHost( NPVariant result; NULL_TO_NPVARIANT(result); - status = NPN_Invoke(NULL, event_obj, init_message_event, init_args, - arraysize(init_args), &result); + status = WebBindings::invoke(NULL, event_obj, init_message_event, init_args, + arraysize(init_args), &result); DCHECK(status) << "Failed to initialize MessageEvent"; - NPN_ReleaseVariantValue(&result); + WebBindings::releaseVariantValue(&result); if (status) { NPVariant event_arg; OBJECT_TO_NPVARIANT(event_obj, event_arg); - status = NPN_InvokeDefault(NULL, on_message_handler_.value.objectValue, - &event_arg, 1, &result); + status = WebBindings::invokeDefault(NULL, + on_message_handler_.value.objectValue, + &event_arg, 1, &result); // Don't DCHECK here in case the reason for the failure is a script error. DLOG_IF(ERROR, !status) << "NPN_InvokeDefault failed"; - NPN_ReleaseVariantValue(&result); + WebBindings::releaseVariantValue(&result); } - NPN_ReleaseObject(event_obj); + WebBindings::releaseObject(event_obj); } return status; @@ -149,11 +153,11 @@ bool ExternalHostBindings::CreateMessageEvent(NPObject** message_event) { }; NPIdentifier identifiers[arraysize(identifier_names)] = {0}; - NPN_GetStringIdentifiers(identifier_names, arraysize(identifier_names), - identifiers); + WebBindings::getStringIdentifiers(identifier_names, + arraysize(identifier_names), identifiers); CppVariant document; - bool ok = NPN_GetProperty(NULL, window, identifiers[0], &document); + bool ok = WebBindings::getProperty(NULL, window, identifiers[0], &document); DCHECK(document.isObject()); bool success = false; @@ -161,8 +165,8 @@ bool ExternalHostBindings::CreateMessageEvent(NPObject** message_event) { NPVariant result, event_type; STRINGN_TO_NPVARIANT("MessageEvent", sizeof("MessageEvent") - 1, \ event_type); - success = NPN_Invoke(NULL, document.value.objectValue, identifiers[1], - &event_type, 1, &result); + success = WebBindings::invoke(NULL, document.value.objectValue, + identifiers[1], &event_type, 1, &result); DCHECK(!success || result.type == NPVariantType_Object); if (result.type != NPVariantType_Object) { DCHECK(success == false); diff --git a/chrome/renderer/webplugin_delegate_proxy.cc b/chrome/renderer/webplugin_delegate_proxy.cc index 5e6ba7a..868be43 100644 --- a/chrome/renderer/webplugin_delegate_proxy.cc +++ b/chrome/renderer/webplugin_delegate_proxy.cc @@ -194,7 +194,7 @@ void WebPluginDelegateProxy::PluginDestroyed() { // When we destroy the plugin instance, the NPObjectStub NULLs out its // pointer to the npobject (see NPObjectStub::OnChannelError). Therefore, // we release the object before destroying the instance to avoid leaking. - NPN_ReleaseObject(npobject_); + WebBindings::releaseObject(npobject_); npobject_ = NULL; } @@ -636,7 +636,7 @@ void WebPluginDelegateProxy::Print(gfx::NativeDrawingContext context) { NPObject* WebPluginDelegateProxy::GetPluginScriptableObject() { if (npobject_) - return NPN_RetainObject(npobject_); + return WebBindings::retainObject(npobject_); int route_id = MSG_ROUTING_NONE; intptr_t npobject_ptr; @@ -649,7 +649,7 @@ NPObject* WebPluginDelegateProxy::GetPluginScriptableObject() { channel_host_.get(), route_id, npobject_ptr, render_view_->modal_dialog_event(), page_url_); - return NPN_RetainObject(npobject_); + return WebBindings::retainObject(npobject_); } void WebPluginDelegateProxy::DidFinishLoadWithReason(NPReason reason) { -- cgit v1.1