Skip to content

Commit

Permalink
Remove scripting from PPP_Instance and PPB_Instance (behind precompil…
Browse files Browse the repository at this point in the history
…er flag).

Create 0.5 versions of the instance interfaces that are the default only if PPAPI_INSTANCE_REMOVE_SCRIPTING is defined.  This is so [hopefully] plugins can opt in to the new version and migrate to InstancePrivate/VarPrivate more easily.

BUG=82606
TEST=PPAPI tests

Review URL: http://codereview.chromium.org/7038044

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@86458 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
dmichael@chromium.org committed May 24, 2011
1 parent be21444 commit 95cfdc8
Show file tree
Hide file tree
Showing 12 changed files with 191 additions and 102 deletions.
58 changes: 22 additions & 36 deletions ppapi/c/ppb_instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@
#include "ppapi/c/pp_var.h"

#define PPB_INSTANCE_INTERFACE_0_4 "PPB_Instance;0.4"
#define PPB_INSTANCE_INTERFACE_0_5 "PPB_Instance;0.5"
#ifdef PPAPI_INSTANCE_REMOVE_SCRIPTING
#define PPB_INSTANCE_INTERFACE PPB_INSTANCE_INTERFACE_0_5
#else
#define PPB_INSTANCE_INTERFACE PPB_INSTANCE_INTERFACE_0_4
#endif

/**
* @file
Expand All @@ -28,25 +33,12 @@
* related to the module instance on a web page.
*
*/
struct PPB_Instance {
/**
* GetWindowObject is a pointer to a function that determines
* the DOM window containing this module instance.
*
* @param[in] instance A PP_Instance whose WindowObject should be retrieved.
* @return A PP_Var containing window object on success.
*/
struct PP_Var (*GetWindowObject)(PP_Instance instance);

/**
* GetOwnerElementObject is a pointer to a function that determines
* the DOM element containing this module instance.
*
* @param[in] instance A PP_Instance whose WindowObject should be retrieved.
* @return A PP_Var containing DOM element on success.
*/
struct PP_Var (*GetOwnerElementObject)(PP_Instance instance);

#ifdef PPAPI_INSTANCE_REMOVE_SCRIPTING
struct PPB_Instance {
#else
struct PPB_Instance_0_5 {
#endif
/**
* BindGraphics is a pointer to a function that binds the given
* graphics as the current drawing surface. The
Expand Down Expand Up @@ -87,28 +79,22 @@ struct PPB_Instance {
*/
PP_Bool (*IsFullFrame)(PP_Instance instance);

/**
* ExecuteScript is a pointer to a function that executes the given
* script in the context of the frame containing the module.
*
* The exception, if any, will be returned in *exception. As with the PPB_Var
* interface, the exception parameter, if non-NULL, must be initialized
* to a void exception or the function will immediately return. On success,
* the exception parameter will be set to a "void" var. On failure, the
* return value will be a "void" var.
*
* @param[in] script A string containing the JavaScript to execute.
* @param[in/out] exception PP_Var containing the exception. Initialize
* this to NULL if you don't want exception info; initialize this to a void
* exception if want exception info.
*
* @return The result of the script execution, or a "void" var
* if execution failed.
*/
};

#ifdef PPAPI_INSTANCE_REMOVE_SCRIPTING
struct PPB_Instance_0_4 {
#else
struct PPB_Instance {
#endif
struct PP_Var (*GetWindowObject)(PP_Instance instance);
struct PP_Var (*GetOwnerElementObject)(PP_Instance instance);
PP_Bool (*BindGraphics)(PP_Instance instance, PP_Resource device);
PP_Bool (*IsFullFrame)(PP_Instance instance);
struct PP_Var (*ExecuteScript)(PP_Instance instance,
struct PP_Var script,
struct PP_Var* exception);
};

/**
* @}
*/
Expand Down
52 changes: 37 additions & 15 deletions ppapi/c/ppp_instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,14 @@
struct PP_InputEvent;
struct PP_Var;

#define PPP_INSTANCE_INTERFACE "PPP_Instance;0.4"
#define PPP_INSTANCE_INTERFACE_0_4 "PPP_Instance;0.4"
#define PPP_INSTANCE_INTERFACE_0_5 "PPP_Instance;0.5"
#ifdef PPAPI_INSTANCE_REMOVE_SCRIPTING
#define PPP_INSTANCE_INTERFACE PPP_INSTANCE_INTERFACE_0_5
#else
#define PPP_INSTANCE_INTERFACE PPP_INSTANCE_INTERFACE_0_4
#endif


/**
* @file
Expand All @@ -33,7 +40,11 @@ struct PP_Var;
* events.
*/

#ifdef PPAPI_INSTANCE_REMOVE_SCRIPTING
struct PPP_Instance {
#else
struct PPP_Instance_0_5 {
#endif
/**
* This value represents a pointer to a function that is called when a new
* module is instantiated on the web page. The identifier of the new
Expand Down Expand Up @@ -159,26 +170,37 @@ struct PPP_Instance {
* @return PP_TRUE if the data was handled, PP_FALSE otherwise.
*/
PP_Bool (*HandleDocumentLoad)(PP_Instance instance, PP_Resource url_loader);
};

/**
* This value represents a pointer to a function that returns a Var
* representing the scriptable object for the given instance. Normally
* this will be a PPP_Class object that exposes certain methods the page
* may want to call.
*
* On Failure, the returned var should be a "void" var.
*
* The returned PP_Var should have a reference added for the caller, which
* will be responsible for Release()ing that reference.
*
* @param[in] instance A PP_Instance indentifying one instance of a module.
* @return A PP_Var containing scriptable object.
*/
#ifdef PPAPI_INSTANCE_REMOVE_SCRIPTING
struct PPP_Instance_0_4 {
#else
struct PPP_Instance {
#endif
PP_Bool (*DidCreate)(PP_Instance instance,
uint32_t argc,
const char* argn[],
const char* argv[]);
void (*DidDestroy)(PP_Instance instance);
void (*DidChangeView)(PP_Instance instance,
const struct PP_Rect* position,
const struct PP_Rect* clip);
void (*DidChangeFocus)(PP_Instance instance, PP_Bool has_focus);
PP_Bool (*HandleInputEvent)(PP_Instance instance,
const struct PP_InputEvent* event);
PP_Bool (*HandleDocumentLoad)(PP_Instance instance, PP_Resource url_loader);
struct PP_Var (*GetInstanceObject)(PP_Instance instance);
};

/**
* @}
*/

#ifdef PPAPI_INSTANCE_REMOVE_SCRIPTING
typedef struct PPP_Instance PPP_Instance_0_5;
#else
typedef struct PPP_Instance PPP_Instance_0_4;
#endif

#endif /* PPAPI_C_PPP_INSTANCE_H_ */

30 changes: 16 additions & 14 deletions ppapi/cpp/instance.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,11 @@ void Instance::HandleMessage(const Var& /*message*/) {
return;
}

Var Instance::GetInstanceObject() {
return Var();
}

Var Instance::GetSelectedText(bool /* html */) {
return Var();
}

#ifndef PPAPI_INSTANCE_REMOVE_SCRIPTING
Var Instance::GetWindowObject() {
if (!has_interface<PPB_Instance>())
return Var();
Expand All @@ -93,6 +90,21 @@ Var Instance::GetOwnerElementObject() {
pp_instance()));
}

Var Instance::ExecuteScript(const Var& script, Var* exception) {
if (!has_interface<PPB_Instance>())
return Var();
return Var(Var::PassRef(),
get_interface<PPB_Instance>()->ExecuteScript(
pp_instance(),
script.pp_var(),
Var::OutException(exception).get()));
}

Var Instance::GetInstanceObject() {
return Var();
}
#endif

bool Instance::BindGraphics(const Graphics2D& graphics) {
if (!has_interface<PPB_Instance>())
return false;
Expand All @@ -114,16 +126,6 @@ bool Instance::IsFullFrame() {
pp_instance()));
}

Var Instance::ExecuteScript(const Var& script, Var* exception) {
if (!has_interface<PPB_Instance>())
return Var();
return Var(Var::PassRef(),
get_interface<PPB_Instance>()->ExecuteScript(
pp_instance(),
script.pp_var(),
Var::OutException(exception).get()));
}

void Instance::PostMessage(const Var& message) {
if (!has_interface<PPB_Messaging>())
return;
Expand Down
14 changes: 8 additions & 6 deletions ppapi/cpp/instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,22 +69,27 @@ class Instance {
/** See PPP_Instance.HandleDocumentLoad. */
virtual bool HandleDocumentLoad(const URLLoader& url_loader);

/** See PPP_Instance.GetInstanceObject. */
virtual Var GetInstanceObject();

/** See PPP_Instance.GetSelectedText. */
virtual Var GetSelectedText(bool html);
// @}

// @{
/** @name PPB_Instance methods for querying the browser: */

#ifndef PPAPI_INSTANCE_REMOVE_SCRIPTING
/** See PPP_Instance.GetInstanceObject. */
virtual Var GetInstanceObject();

/** See PPB_Instance.GetWindowObject. */
Var GetWindowObject();

/** See PPB_Instance.GetOwnerElementObject. */
Var GetOwnerElementObject();

/** See PPB_Instance.ExecuteScript. */
Var ExecuteScript(const Var& script, Var* exception = NULL);
#endif

/** See PPB_Instance.BindGraphics. */
bool BindGraphics(const Graphics2D& graphics);

Expand All @@ -94,9 +99,6 @@ class Instance {
/** See PPB_Instance.IsFullFrame. */
bool IsFullFrame();

/** See PPB_Instance.ExecuteScript. */
Var ExecuteScript(const Var& script, Var* exception = NULL);

// These functions use the PPP_Messaging and PPB_Messaging interfaces, so that
// messaging can be done conveniently for a pp::Instance without using a
// separate C++ class.
Expand Down
4 changes: 4 additions & 0 deletions ppapi/cpp/module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ PP_Bool Instance_HandleDocumentLoad(PP_Instance pp_instance,
instance->HandleDocumentLoad(URLLoader(pp_url_loader)));
}

#ifndef PPAPI_INSTANCE_REMOVE_SCRIPTING
PP_Var Instance_GetInstanceObject(PP_Instance pp_instance) {
Module* module_singleton = Module::Get();
if (!module_singleton)
Expand All @@ -124,6 +125,7 @@ PP_Var Instance_GetInstanceObject(PP_Instance pp_instance) {
return Var().Detach();
return instance->GetInstanceObject().Detach();
}
#endif

static PPP_Instance instance_interface = {
&Instance_DidCreate,
Expand All @@ -132,7 +134,9 @@ static PPP_Instance instance_interface = {
&Instance_DidChangeFocus,
&Instance_HandleInputEvent,
&Instance_HandleDocumentLoad,
#ifndef PPAPI_INSTANCE_REMOVE_SCRIPTING
&Instance_GetInstanceObject
#endif
};

void Messaging_HandleMessage(PP_Instance pp_instance, PP_Var var) {
Expand Down
5 changes: 5 additions & 0 deletions webkit/glue/webkit_glue.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@
'target_name': 'glue',
'type': 'static_library',
'msvs_guid': 'C66B126D-0ECE-4CA2-B6DC-FA780AFBBF09',
#TODO(dmichael): Remove this #define once all plugins are ported from
# PPP_Instance and PPB_Instance scripting functions.
'defines': [
'PPAPI_INSTANCE_REMOVE_SCRIPTING',
],
'dependencies': [
'<(DEPTH)/app/app.gyp:app_base',
'<(DEPTH)/base/base.gyp:base_i18n',
Expand Down
35 changes: 27 additions & 8 deletions webkit/plugins/ppapi/plugin_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -229,12 +229,20 @@ const PPB_Testing_Dev testing_interface = {
&GetLiveObjectsForInstance
};

// Return the part of the interface name before the ';' separator.
// If there is no ';', just returns the whole string.
std::string GetInterfacePrefix(const std::string& interface_string) {
size_t separator_pos = interface_string.find_first_of(';');
return interface_string.substr(0, separator_pos);
}

// GetInterface ----------------------------------------------------------------

const void* GetInterface(const char* name) {
// All interfaces should be used on the main thread.
DCHECK(IsMainThread());

std::string name_prefix(GetInterfacePrefix(name));
// Please keep alphabetized by interface macro name with "special" stuff at
// the bottom.
if (strcmp(name, PPB_AUDIO_CONFIG_INTERFACE) == 0)
Expand Down Expand Up @@ -293,8 +301,8 @@ const void* GetInterface(const char* name) {
return PPB_ImageData_Impl::GetInterface();
if (strcmp(name, PPB_IMAGEDATA_TRUSTED_INTERFACE) == 0)
return PPB_ImageData_Impl::GetTrustedInterface();
if (strcmp(name, PPB_INSTANCE_INTERFACE) == 0)
return PluginInstance::GetInterface();
if (name_prefix == GetInterfacePrefix(PPB_INSTANCE_INTERFACE))
return PluginInstance::GetInterface(name);
if (strcmp(name, PPB_INSTANCE_PRIVATE_INTERFACE) == 0)
return PluginInstance::GetPrivateInterface();
if (strcmp(name, PPB_MESSAGING_INTERFACE) == 0)
Expand Down Expand Up @@ -488,15 +496,26 @@ PluginModule::GetInterfaceFunc PluginModule::GetLocalGetInterfaceFunc() {
}

PluginInstance* PluginModule::CreateInstance(PluginDelegate* delegate) {
const PPP_Instance* plugin_instance_interface =
reinterpret_cast<const PPP_Instance*>(GetPluginInterface(
PPP_INSTANCE_INTERFACE));
if (!plugin_instance_interface) {
PluginInstance* instance(NULL);
const void* plugin_instance_if = GetPluginInterface(PPP_INSTANCE_INTERFACE);
if (plugin_instance_if) {
instance = new PluginInstance(delegate, this,
PluginInstance::new_instance_interface<PPP_Instance>(
plugin_instance_if));
} else {
// If the current interface is not supported, try retrieving older versions.
const void* instance_if_0_4 =
GetPluginInterface(PPP_INSTANCE_INTERFACE_0_4);
if (instance_if_0_4) {
instance = new PluginInstance(delegate, this,
PluginInstance::new_instance_interface<PPP_Instance_0_4>(
instance_if_0_4));
}
}
if (!instance) {
LOG(WARNING) << "Plugin doesn't support instance interface, failing.";
return NULL;
}
PluginInstance* instance = new PluginInstance(delegate, this,
plugin_instance_interface);
if (out_of_process_proxy_.get())
out_of_process_proxy_->AddInstance(instance->pp_instance());
return instance;
Expand Down
Loading

0 comments on commit 95cfdc8

Please sign in to comment.