summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-08 22:57:18 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-08 22:57:18 +0000
commit1deed85adce1b9dcd1e133eb591331f49092aad2 (patch)
treeccfd2f40ca4d1cccb8dd68d9fba74a1c742293a2
parent552751a35b96a59a945677b892a5e15c06ffce7d (diff)
downloadchromium_src-1deed85adce1b9dcd1e133eb591331f49092aad2.zip
chromium_src-1deed85adce1b9dcd1e133eb591331f49092aad2.tar.gz
chromium_src-1deed85adce1b9dcd1e133eb591331f49092aad2.tar.bz2
Convert pepper module and instance IDs from being pointer values to being
random numbers. BUG=57330 TEST=none Review URL: http://codereview.chromium.org/3571022 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@62037 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--webkit/glue/plugins/pepper_audio.cc4
-rw-r--r--webkit/glue/plugins/pepper_buffer.cc2
-rw-r--r--webkit/glue/plugins/pepper_char_set.cc2
-rw-r--r--webkit/glue/plugins/pepper_cursor_control.cc10
-rw-r--r--webkit/glue/plugins/pepper_file_chooser.cc2
-rw-r--r--webkit/glue/plugins/pepper_file_io.cc2
-rw-r--r--webkit/glue/plugins/pepper_file_ref.cc2
-rw-r--r--webkit/glue/plugins/pepper_font.cc2
-rw-r--r--webkit/glue/plugins/pepper_graphics_2d.cc2
-rw-r--r--webkit/glue/plugins/pepper_graphics_3d.cc6
-rw-r--r--webkit/glue/plugins/pepper_image_data.cc2
-rw-r--r--webkit/glue/plugins/pepper_plugin_instance.cc74
-rw-r--r--webkit/glue/plugins/pepper_plugin_instance.h13
-rw-r--r--webkit/glue/plugins/pepper_plugin_module.cc23
-rw-r--r--webkit/glue/plugins/pepper_plugin_module.h13
-rw-r--r--webkit/glue/plugins/pepper_private.cc6
-rw-r--r--webkit/glue/plugins/pepper_private2.cc2
-rw-r--r--webkit/glue/plugins/pepper_resource_tracker.cc75
-rw-r--r--webkit/glue/plugins/pepper_resource_tracker.h44
-rw-r--r--webkit/glue/plugins/pepper_scrollbar.cc4
-rw-r--r--webkit/glue/plugins/pepper_url_loader.cc3
-rw-r--r--webkit/glue/plugins/pepper_url_request_info.cc2
-rw-r--r--webkit/glue/plugins/pepper_url_util.cc4
-rw-r--r--webkit/glue/plugins/pepper_var.cc4
-rw-r--r--webkit/glue/plugins/pepper_video_decoder.cc4
-rw-r--r--webkit/glue/plugins/pepper_widget.cc2
26 files changed, 211 insertions, 98 deletions
diff --git a/webkit/glue/plugins/pepper_audio.cc b/webkit/glue/plugins/pepper_audio.cc
index ce617e2..b838ddf 100644
--- a/webkit/glue/plugins/pepper_audio.cc
+++ b/webkit/glue/plugins/pepper_audio.cc
@@ -18,7 +18,7 @@ PP_Resource CreateStereo16bit(PP_Module module_id,
PP_AudioSampleRate_Dev sample_rate,
uint32_t sample_frame_count,
uint32_t* obtained_frame_count) {
- PluginModule* module = PluginModule::FromPPModule(module_id);
+ PluginModule* module = ResourceTracker::Get()->GetModule(module_id);
if (!module)
return 0;
@@ -43,7 +43,7 @@ uint32_t GetSampleFrameCount(PP_Resource config_id) {
PP_Resource Create(PP_Instance instance_id, PP_Resource config_id,
PPB_Audio_Callback callback, void* user_data) {
- PluginInstance* instance = PluginInstance::FromPPInstance(instance_id);
+ PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id);
if (!instance)
return 0;
// TODO(neb): Require callback to be present for untrusted plugins.
diff --git a/webkit/glue/plugins/pepper_buffer.cc b/webkit/glue/plugins/pepper_buffer.cc
index c3acef8..1b9097d 100644
--- a/webkit/glue/plugins/pepper_buffer.cc
+++ b/webkit/glue/plugins/pepper_buffer.cc
@@ -20,7 +20,7 @@ namespace pepper {
namespace {
PP_Resource Create(PP_Module module_id, int32_t size) {
- PluginModule* module = PluginModule::FromPPModule(module_id);
+ PluginModule* module = ResourceTracker::Get()->GetModule(module_id);
if (!module)
return 0;
diff --git a/webkit/glue/plugins/pepper_char_set.cc b/webkit/glue/plugins/pepper_char_set.cc
index 1518069..043de41 100644
--- a/webkit/glue/plugins/pepper_char_set.cc
+++ b/webkit/glue/plugins/pepper_char_set.cc
@@ -141,7 +141,7 @@ uint16_t* CharSetToUTF16(const char* input, uint32_t input_len,
}
PP_Var GetDefaultCharSet(PP_Module pp_module) {
- PluginModule* module = PluginModule::FromPPModule(pp_module);
+ PluginModule* module = ResourceTracker::Get()->GetModule(pp_module);
if (!module)
return PP_MakeUndefined();
diff --git a/webkit/glue/plugins/pepper_cursor_control.cc b/webkit/glue/plugins/pepper_cursor_control.cc
index de3c166..687aa76 100644
--- a/webkit/glue/plugins/pepper_cursor_control.cc
+++ b/webkit/glue/plugins/pepper_cursor_control.cc
@@ -22,7 +22,7 @@ bool SetCursor(PP_Instance instance_id,
PP_CursorType_Dev type,
PP_Resource custom_image_id,
const PP_Point* hot_spot) {
- PluginInstance* instance = PluginInstance::FromPPInstance(instance_id);
+ PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id);
if (!instance)
return false;
@@ -38,7 +38,7 @@ bool SetCursor(PP_Instance instance_id,
}
bool LockCursor(PP_Instance instance_id) {
- PluginInstance* instance = PluginInstance::FromPPInstance(instance_id);
+ PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id);
if (!instance)
return false;
@@ -47,7 +47,7 @@ bool LockCursor(PP_Instance instance_id) {
}
bool UnlockCursor(PP_Instance instance_id) {
- PluginInstance* instance = PluginInstance::FromPPInstance(instance_id);
+ PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id);
if (!instance)
return false;
@@ -56,7 +56,7 @@ bool UnlockCursor(PP_Instance instance_id) {
}
bool HasCursorLock(PP_Instance instance_id) {
- PluginInstance* instance = PluginInstance::FromPPInstance(instance_id);
+ PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id);
if (!instance)
return false;
@@ -65,7 +65,7 @@ bool HasCursorLock(PP_Instance instance_id) {
}
bool CanLockCursor(PP_Instance instance_id) {
- PluginInstance* instance = PluginInstance::FromPPInstance(instance_id);
+ PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id);
if (!instance)
return false;
diff --git a/webkit/glue/plugins/pepper_file_chooser.cc b/webkit/glue/plugins/pepper_file_chooser.cc
index 138efd7..12b04a4 100644
--- a/webkit/glue/plugins/pepper_file_chooser.cc
+++ b/webkit/glue/plugins/pepper_file_chooser.cc
@@ -33,7 +33,7 @@ namespace {
PP_Resource Create(PP_Instance instance_id,
const PP_FileChooserOptions_Dev* options) {
- PluginInstance* instance = PluginInstance::FromPPInstance(instance_id);
+ PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id);
if (!instance)
return 0;
diff --git a/webkit/glue/plugins/pepper_file_io.cc b/webkit/glue/plugins/pepper_file_io.cc
index 9090f88..9d26899 100644
--- a/webkit/glue/plugins/pepper_file_io.cc
+++ b/webkit/glue/plugins/pepper_file_io.cc
@@ -25,7 +25,7 @@ namespace pepper {
namespace {
PP_Resource Create(PP_Module module_id) {
- PluginModule* module = PluginModule::FromPPModule(module_id);
+ PluginModule* module = ResourceTracker::Get()->GetModule(module_id);
if (!module)
return 0;
diff --git a/webkit/glue/plugins/pepper_file_ref.cc b/webkit/glue/plugins/pepper_file_ref.cc
index 971a36e..5ff6f8e 100644
--- a/webkit/glue/plugins/pepper_file_ref.cc
+++ b/webkit/glue/plugins/pepper_file_ref.cc
@@ -37,7 +37,7 @@ void TrimTrailingSlash(std::string* path) {
PP_Resource CreateFileRef(PP_Instance instance_id,
PP_FileSystemType_Dev fs_type,
const char* path) {
- PluginInstance* instance = PluginInstance::FromPPInstance(instance_id);
+ PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id);
if (!instance)
return 0;
diff --git a/webkit/glue/plugins/pepper_font.cc b/webkit/glue/plugins/pepper_font.cc
index 94e9ac7..cad39f5 100644
--- a/webkit/glue/plugins/pepper_font.cc
+++ b/webkit/glue/plugins/pepper_font.cc
@@ -108,7 +108,7 @@ bool PPTextRunToWebTextRun(const PP_TextRun_Dev* run, WebTextRun* output) {
PP_Resource Create(PP_Module module_id,
const PP_FontDescription_Dev* description) {
- PluginModule* module = PluginModule::FromPPModule(module_id);
+ PluginModule* module = ResourceTracker::Get()->GetModule(module_id);
if (!module)
return 0;
diff --git a/webkit/glue/plugins/pepper_graphics_2d.cc b/webkit/glue/plugins/pepper_graphics_2d.cc
index 66cc70c..c122b5c 100644
--- a/webkit/glue/plugins/pepper_graphics_2d.cc
+++ b/webkit/glue/plugins/pepper_graphics_2d.cc
@@ -66,7 +66,7 @@ bool ValidateAndConvertRect(const PP_Rect* rect,
PP_Resource Create(PP_Module module_id,
const PP_Size* size,
bool is_always_opaque) {
- PluginModule* module = PluginModule::FromPPModule(module_id);
+ PluginModule* module = ResourceTracker::Get()->GetModule(module_id);
if (!module)
return 0;
diff --git a/webkit/glue/plugins/pepper_graphics_3d.cc b/webkit/glue/plugins/pepper_graphics_3d.cc
index 18e5cd1..1ebc3ea 100644
--- a/webkit/glue/plugins/pepper_graphics_3d.cc
+++ b/webkit/glue/plugins/pepper_graphics_3d.cc
@@ -62,7 +62,7 @@ PP_Resource CreateContext(PP_Instance instance_id, int32_t config,
const int32_t* attrib_list) {
DCHECK_EQ(0, share_context);
- PluginInstance* instance = PluginInstance::FromPPInstance(instance_id);
+ PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id);
if (!instance) {
return 0;
}
@@ -146,7 +146,7 @@ Graphics3D::~Graphics3D() {
bool Graphics3D::Init(PP_Instance instance_id, int32_t config,
const int32_t* attrib_list) {
- PluginInstance* instance = PluginInstance::FromPPInstance(instance_id);
+ PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id);
if (!instance) {
return false;
}
@@ -241,7 +241,7 @@ void Graphics3D::Destroy() {
}
void Graphics3D::HandleRepaint(PP_Instance instance_id) {
- PluginInstance* instance = PluginInstance::FromPPInstance(instance_id);
+ PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id);
if (instance) {
instance->Graphics3DContextLost();
if (platform_context_.get()) {
diff --git a/webkit/glue/plugins/pepper_image_data.cc b/webkit/glue/plugins/pepper_image_data.cc
index 1a6882c..8c9bc08 100644
--- a/webkit/glue/plugins/pepper_image_data.cc
+++ b/webkit/glue/plugins/pepper_image_data.cc
@@ -34,7 +34,7 @@ PP_Resource Create(PP_Module module_id,
PP_ImageDataFormat format,
const PP_Size* size,
bool init_to_zero) {
- PluginModule* module = PluginModule::FromPPModule(module_id);
+ PluginModule* module = ResourceTracker::Get()->GetModule(module_id);
if (!module)
return 0;
diff --git a/webkit/glue/plugins/pepper_plugin_instance.cc b/webkit/glue/plugins/pepper_plugin_instance.cc
index cadf4de..fb251e0 100644
--- a/webkit/glue/plugins/pepper_plugin_instance.cc
+++ b/webkit/glue/plugins/pepper_plugin_instance.cc
@@ -141,28 +141,28 @@ void RectToPPRect(const gfx::Rect& input, PP_Rect* output) {
}
PP_Var GetWindowObject(PP_Instance instance_id) {
- PluginInstance* instance = PluginInstance::FromPPInstance(instance_id);
+ PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id);
if (!instance)
return PP_MakeUndefined();
return instance->GetWindowObject();
}
PP_Var GetOwnerElementObject(PP_Instance instance_id) {
- PluginInstance* instance = PluginInstance::FromPPInstance(instance_id);
+ PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id);
if (!instance)
return PP_MakeUndefined();
return instance->GetOwnerElementObject();
}
bool BindGraphics(PP_Instance instance_id, PP_Resource device_id) {
- PluginInstance* instance = PluginInstance::FromPPInstance(instance_id);
+ PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id);
if (!instance)
return false;
return instance->BindGraphics(device_id);
}
bool IsFullFrame(PP_Instance instance_id) {
- PluginInstance* instance = PluginInstance::FromPPInstance(instance_id);
+ PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id);
if (!instance)
return false;
return instance->full_frame();
@@ -171,7 +171,7 @@ bool IsFullFrame(PP_Instance instance_id) {
PP_Var ExecuteScript(PP_Instance instance_id,
PP_Var script,
PP_Var* exception) {
- PluginInstance* instance = PluginInstance::FromPPInstance(instance_id);
+ PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id);
if (!instance)
return PP_MakeUndefined();
return instance->ExecuteScript(script, exception);
@@ -188,7 +188,7 @@ const PPB_Instance ppb_instance = {
void NumberOfFindResultsChanged(PP_Instance instance_id,
int32_t total,
bool final_result) {
- PluginInstance* instance = PluginInstance::FromPPInstance(instance_id);
+ PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id);
if (!instance)
return;
@@ -199,7 +199,7 @@ void NumberOfFindResultsChanged(PP_Instance instance_id,
void SelectedFindResultChanged(PP_Instance instance_id,
int32_t index) {
- PluginInstance* instance = PluginInstance::FromPPInstance(instance_id);
+ PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id);
if (!instance)
return;
@@ -214,14 +214,14 @@ const PPB_Find_Dev ppb_find = {
};
bool IsFullscreen(PP_Instance instance_id) {
- PluginInstance* instance = PluginInstance::FromPPInstance(instance_id);
+ PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id);
if (!instance)
return false;
return instance->IsFullscreen();
}
bool SetFullscreen(PP_Instance instance_id, bool fullscreen) {
- PluginInstance* instance = PluginInstance::FromPPInstance(instance_id);
+ PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id);
if (!instance)
return false;
return instance->SetFullscreen(fullscreen);
@@ -233,7 +233,7 @@ const PPB_Fullscreen_Dev ppb_fullscreen = {
};
void ZoomChanged(PP_Instance instance_id, double factor) {
- PluginInstance* instance = PluginInstance::FromPPInstance(instance_id);
+ PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id);
if (!instance)
return;
double zoom_level = WebView::zoomFactorToZoomLevel(factor);
@@ -248,7 +248,7 @@ void ZoomLimitsChanged(PP_Instance instance_id,
return;
}
- PluginInstance* instance = PluginInstance::FromPPInstance(instance_id);
+ PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id);
if (!instance)
return;
instance->delegate()->ZoomLimitsChanged(minimum_factor, maximium_factor);
@@ -267,6 +267,7 @@ PluginInstance::PluginInstance(PluginDelegate* delegate,
: delegate_(delegate),
module_(module),
instance_interface_(instance_interface),
+ pp_instance_(0),
container_(NULL),
full_frame_(false),
has_webkit_focus_(false),
@@ -283,6 +284,8 @@ PluginInstance::PluginInstance(PluginDelegate* delegate,
plugin_graphics_3d_interface_(NULL),
always_on_top_(false),
fullscreen_container_(NULL) {
+ pp_instance_ = ResourceTracker::Get()->AddInstance(this);
+
memset(&current_print_settings_, 0, sizeof(current_print_settings_));
DCHECK(delegate);
module_->InstanceCreated(this);
@@ -292,6 +295,8 @@ PluginInstance::PluginInstance(PluginDelegate* delegate,
PluginInstance::~PluginInstance() {
delegate_->InstanceDeleted(this);
module_->InstanceDeleted(this);
+
+ ResourceTracker::Get()->InstanceDeleted(pp_instance_);
}
// static
@@ -300,11 +305,6 @@ const PPB_Instance* PluginInstance::GetInterface() {
}
// static
-PluginInstance* PluginInstance::FromPPInstance(PP_Instance instance) {
- return reinterpret_cast<PluginInstance*>(instance);
-}
-
-// static
const PPB_Find_Dev* PluginInstance::GetFindInterface() {
return &ppb_find;
}
@@ -319,10 +319,6 @@ const PPB_Zoom_Dev* PluginInstance::GetZoomInterface() {
return &ppb_zoom;
}
-PP_Instance PluginInstance::GetPPInstance() {
- return reinterpret_cast<intptr_t>(this);
-}
-
void PluginInstance::Paint(WebCanvas* canvas,
const gfx::Rect& plugin_rect,
const gfx::Rect& paint_rect) {
@@ -451,7 +447,7 @@ PP_Var PluginInstance::ExecuteScript(PP_Var script, PP_Var* exception) {
}
void PluginInstance::Delete() {
- instance_interface_->DidDestroy(GetPPInstance());
+ instance_interface_->DidDestroy(pp_instance());
if (fullscreen_container_) {
fullscreen_container_->Destroy();
@@ -476,13 +472,13 @@ bool PluginInstance::Initialize(WebPluginContainer* container,
argc++;
}
- return instance_interface_->DidCreate(GetPPInstance(),
+ return instance_interface_->DidCreate(pp_instance(),
argc, argn.get(), argv.get());
}
bool PluginInstance::HandleDocumentLoad(URLLoader* loader) {
Resource::ScopedResourceId resource(loader);
- return instance_interface_->HandleDocumentLoad(GetPPInstance(), resource.id);
+ return instance_interface_->HandleDocumentLoad(pp_instance(), resource.id);
}
bool PluginInstance::HandleInputEvent(const WebKit::WebInputEvent& event,
@@ -493,7 +489,7 @@ bool PluginInstance::HandleInputEvent(const WebKit::WebInputEvent& event,
// Each input event may generate more than one PP_InputEvent.
bool rv = false;
for (size_t i = 0; i < pp_events.size(); i++)
- rv |= instance_interface_->HandleInputEvent(GetPPInstance(), &pp_events[i]);
+ rv |= instance_interface_->HandleInputEvent(pp_instance(), &pp_events[i]);
if (cursor_.get())
*cursor_info = *cursor_;
@@ -501,7 +497,7 @@ bool PluginInstance::HandleInputEvent(const WebKit::WebInputEvent& event,
}
PP_Var PluginInstance::GetInstanceObject() {
- return instance_interface_->GetInstanceObject(GetPPInstance());
+ return instance_interface_->GetInstanceObject(pp_instance());
}
void PluginInstance::ViewChanged(const gfx::Rect& position,
@@ -520,7 +516,7 @@ void PluginInstance::ViewChanged(const gfx::Rect& position,
PP_Rect pp_position, pp_clip;
RectToPPRect(position_, &pp_position);
RectToPPRect(clip_, &pp_clip);
- instance_interface_->DidChangeView(GetPPInstance(), &pp_position, &pp_clip);
+ instance_interface_->DidChangeView(pp_instance(), &pp_position, &pp_clip);
}
void PluginInstance::SetWebKitFocus(bool has_focus) {
@@ -530,7 +526,7 @@ void PluginInstance::SetWebKitFocus(bool has_focus) {
bool old_plugin_focus = PluginHasFocus();
has_webkit_focus_ = has_focus;
if (PluginHasFocus() != old_plugin_focus)
- instance_interface_->DidChangeFocus(GetPPInstance(), PluginHasFocus());
+ instance_interface_->DidChangeFocus(pp_instance(), PluginHasFocus());
}
void PluginInstance::SetContentAreaFocus(bool has_focus) {
@@ -540,7 +536,7 @@ void PluginInstance::SetContentAreaFocus(bool has_focus) {
bool old_plugin_focus = PluginHasFocus();
has_content_area_focus_ = has_focus;
if (PluginHasFocus() != old_plugin_focus)
- instance_interface_->DidChangeFocus(GetPPInstance(), PluginHasFocus());
+ instance_interface_->DidChangeFocus(pp_instance(), PluginHasFocus());
}
void PluginInstance::ViewInitiatedPaint() {
@@ -581,7 +577,7 @@ bool PluginInstance::GetBitmapForOptimizedPluginPaint(
}
string16 PluginInstance::GetSelectedText(bool html) {
- PP_Var rv = instance_interface_->GetSelectedText(GetPPInstance(), html);
+ PP_Var rv = instance_interface_->GetSelectedText(pp_instance(), html);
scoped_refptr<StringVar> string(StringVar::FromPPVar(rv));
Var::PluginReleasePPVar(rv); // Release the ref the plugin transfered to us.
if (!string)
@@ -596,7 +592,7 @@ string16 PluginInstance::GetLinkAtPosition(const gfx::Point& point) {
PP_Point p;
p.x = point.x();
p.y = point.y();
- PP_Var rv = plugin_private_interface_->GetLinkAtPosition(GetPPInstance(), p);
+ PP_Var rv = plugin_private_interface_->GetLinkAtPosition(pp_instance(), p);
scoped_refptr<StringVar> string(StringVar::FromPPVar(rv));
Var::PluginReleasePPVar(rv); // Release the ref the plugin transfered to us.
if (!string)
@@ -607,7 +603,7 @@ string16 PluginInstance::GetLinkAtPosition(const gfx::Point& point) {
void PluginInstance::Zoom(double factor, bool text_only) {
if (!LoadZoomInterface())
return;
- plugin_zoom_interface_->Zoom(GetPPInstance(), factor, text_only);
+ plugin_zoom_interface_->Zoom(pp_instance(), factor, text_only);
}
bool PluginInstance::StartFind(const string16& search_text,
@@ -617,21 +613,21 @@ bool PluginInstance::StartFind(const string16& search_text,
return false;
find_identifier_ = identifier;
return plugin_find_interface_->StartFind(
- GetPPInstance(),
+ pp_instance(),
UTF16ToUTF8(search_text.c_str()).c_str(),
case_sensitive);
}
void PluginInstance::SelectFindResult(bool forward) {
if (LoadFindInterface())
- plugin_find_interface_->SelectFindResult(GetPPInstance(), forward);
+ plugin_find_interface_->SelectFindResult(pp_instance(), forward);
}
void PluginInstance::StopFind() {
if (!LoadFindInterface())
return;
find_identifier_ = -1;
- plugin_find_interface_->StopFind(GetPPInstance());
+ plugin_find_interface_->StopFind(pp_instance());
}
bool PluginInstance::LoadFindInterface() {
@@ -679,7 +675,7 @@ bool PluginInstance::GetPreferredPrintOutputFormat(
return false;
uint32_t format_count = 0;
PP_PrintOutputFormat_Dev* supported_formats =
- plugin_print_interface_->QuerySupportedFormats(GetPPInstance(),
+ plugin_print_interface_->QuerySupportedFormats(pp_instance(),
&format_count);
if (!supported_formats)
return false;
@@ -722,7 +718,7 @@ int PluginInstance::PrintBegin(const gfx::Rect& printable_area,
print_settings.orientation = PP_PRINTORIENTATION_NORMAL;
print_settings.grayscale = false;
print_settings.format = format;
- int num_pages = plugin_print_interface_->Begin(GetPPInstance(),
+ int num_pages = plugin_print_interface_->Begin(pp_instance(),
&print_settings);
if (!num_pages)
return 0;
@@ -753,7 +749,7 @@ bool PluginInstance::PrintPage(int page_number, WebKit::WebCanvas* canvas) {
#endif // defined(OS_LINUX)
PP_Resource print_output =
- plugin_print_interface_->PrintPages(GetPPInstance(), &page_range, 1);
+ plugin_print_interface_->PrintPages(pp_instance(), &page_range, 1);
if (!print_output)
return false;
@@ -774,7 +770,7 @@ bool PluginInstance::PrintPage(int page_number, WebKit::WebCanvas* canvas) {
void PluginInstance::PrintEnd() {
DCHECK(plugin_print_interface_);
if (plugin_print_interface_)
- plugin_print_interface_->End(GetPPInstance());
+ plugin_print_interface_->End(pp_instance());
memset(&current_print_settings_, 0, sizeof(current_print_settings_));
#if defined(OS_MACOSX)
last_printed_page_ = NULL;
@@ -791,7 +787,7 @@ void PluginInstance::Graphics3DContextLost() {
PPP_GRAPHICS_3D_DEV_INTERFACE));
}
if (plugin_graphics_3d_interface_)
- plugin_graphics_3d_interface_->Graphics3DContextLost(GetPPInstance());
+ plugin_graphics_3d_interface_->Graphics3DContextLost(pp_instance());
}
bool PluginInstance::IsFullscreen() {
diff --git a/webkit/glue/plugins/pepper_plugin_instance.h b/webkit/glue/plugins/pepper_plugin_instance.h
index 1604171..197d944 100644
--- a/webkit/glue/plugins/pepper_plugin_instance.h
+++ b/webkit/glue/plugins/pepper_plugin_instance.h
@@ -53,6 +53,10 @@ class PluginModule;
class URLLoader;
class FullscreenContainer;
+// Represents one time a plugin appears on one web page.
+//
+// Note: to get from a PP_Instance to a PluginInstance*, use the
+// ResourceTracker.
class PluginInstance : public base::RefCounted<PluginInstance> {
public:
PluginInstance(PluginDelegate* delegate,
@@ -62,9 +66,6 @@ class PluginInstance : public base::RefCounted<PluginInstance> {
static const PPB_Instance* GetInterface();
- // Converts the given instance ID to an actual instance object.
- static PluginInstance* FromPPInstance(PP_Instance instance);
-
// Returns a pointer to the interface implementing PPB_Find that is
// exposed to the plugin.
static const PPB_Find_Dev* GetFindInterface();
@@ -83,7 +84,9 @@ class PluginInstance : public base::RefCounted<PluginInstance> {
void set_always_on_top(bool on_top) { always_on_top_ = on_top; }
- PP_Instance GetPPInstance();
+ // Returns the PP_Instance uniquely identifying this instance. Guaranteed
+ // nonzero.
+ PP_Instance pp_instance() const { return pp_instance_; }
// Paints the current backing store to the web page.
void Paint(WebKit::WebCanvas* canvas,
@@ -186,6 +189,8 @@ class PluginInstance : public base::RefCounted<PluginInstance> {
scoped_refptr<PluginModule> module_;
const PPP_Instance* instance_interface_;
+ PP_Instance pp_instance_;
+
// NULL until we have been initialized.
WebKit::WebPluginContainer* container_;
diff --git a/webkit/glue/plugins/pepper_plugin_module.cc b/webkit/glue/plugins/pepper_plugin_module.cc
index 99047bf..d54eaa1 100644
--- a/webkit/glue/plugins/pepper_plugin_module.cc
+++ b/webkit/glue/plugins/pepper_plugin_module.cc
@@ -179,21 +179,21 @@ void QuitMessageLoop() {
}
uint32_t GetLiveObjectCount(PP_Module module_id) {
- PluginModule* module = PluginModule::FromPPModule(module_id);
+ PluginModule* module = ResourceTracker::Get()->GetModule(module_id);
if (!module)
return static_cast<uint32_t>(-1);
return ResourceTracker::Get()->GetLiveObjectsForModule(module);
}
PP_Resource GetInaccessibleFileRef(PP_Module module_id) {
- PluginModule* module = PluginModule::FromPPModule(module_id);
+ PluginModule* module = ResourceTracker::Get()->GetModule(module_id);
if (!module)
return static_cast<uint32_t>(-1);
return FileRef::GetInaccessibleFileRef(module)->GetReference();
}
PP_Resource GetNonexistentFileRef(PP_Module module_id) {
- PluginModule* module = PluginModule::FromPPModule(module_id);
+ PluginModule* module = ResourceTracker::Get()->GetModule(module_id);
if (!module)
return static_cast<uint32_t>(-1);
return FileRef::GetNonexistentFileRef(module)->GetReference();
@@ -299,6 +299,7 @@ const void* GetInterface(const char* name) {
PluginModule::PluginModule()
: initialized_(false),
library_(NULL) {
+ pp_module_ = ResourceTracker::Get()->AddModule(this);
GetMainThreadMessageLoop(); // Initialize the main thread message loop.
GetLivePluginSet()->insert(this);
}
@@ -326,6 +327,8 @@ PluginModule::~PluginModule() {
if (library_)
base::UnloadNativeLibrary(library_);
+
+ ResourceTracker::Get()->ModuleDeleted(pp_module_);
}
// static
@@ -350,14 +353,6 @@ scoped_refptr<PluginModule> PluginModule::CreateInternalModule(
}
// static
-PluginModule* PluginModule::FromPPModule(PP_Module module) {
- PluginModule* lib = reinterpret_cast<PluginModule*>(module);
- if (GetLivePluginSet()->find(lib) == GetLivePluginSet()->end())
- return NULL; // Invalid plugin.
- return lib;
-}
-
-// static
const PPB_Core* PluginModule::GetCore() {
return &core_interface;
}
@@ -367,7 +362,7 @@ bool PluginModule::InitFromEntryPoints(const EntryPoints& entry_points) {
return true;
// Attempt to run the initialization funciton.
- int retval = entry_points.initialize_module(GetPPModule(), &GetInterface);
+ int retval = entry_points.initialize_module(pp_module(), &GetInterface);
if (retval != 0) {
LOG(WARNING) << "PPP_InitializeModule returned failure " << retval;
return false;
@@ -431,10 +426,6 @@ bool PluginModule::LoadEntryPoints(const base::NativeLibrary& library,
return true;
}
-PP_Module PluginModule::GetPPModule() const {
- return reinterpret_cast<intptr_t>(this);
-}
-
PluginInstance* PluginModule::CreateInstance(PluginDelegate* delegate) {
const PPP_Instance* plugin_instance_interface =
reinterpret_cast<const PPP_Instance*>(GetPluginInterface(
diff --git a/webkit/glue/plugins/pepper_plugin_module.h b/webkit/glue/plugins/pepper_plugin_module.h
index a560c56..edb9e12 100644
--- a/webkit/glue/plugins/pepper_plugin_module.h
+++ b/webkit/glue/plugins/pepper_plugin_module.h
@@ -27,6 +27,11 @@ class PluginDelegate;
class PluginInstance;
class PluginObject;
+// Represents one plugin library loaded into one renderer. This library may
+// have multiple instances.
+//
+// Note: to get from a PP_Instance to a PluginInstance*, use the
+// ResourceTracker.
class PluginModule : public base::RefCounted<PluginModule>,
public base::SupportsWeakPtr<PluginModule> {
public:
@@ -52,13 +57,9 @@ class PluginModule : public base::RefCounted<PluginModule>,
static scoped_refptr<PluginModule> CreateInternalModule(
EntryPoints entry_points);
- // Converts the given module ID to an actual module object. Will return NULL
- // if the module is invalid.
- static PluginModule* FromPPModule(PP_Module module);
-
static const PPB_Core* GetCore();
- PP_Module GetPPModule() const;
+ PP_Module pp_module() const { return pp_module_; }
PluginInstance* CreateInstance(PluginDelegate* delegate);
@@ -100,6 +101,8 @@ class PluginModule : public base::RefCounted<PluginModule>,
static bool LoadEntryPoints(const base::NativeLibrary& library,
EntryPoints* entry_points);
+ PP_Module pp_module_;
+
bool initialized_;
// Holds a reference to the base::NativeLibrary handle if this PluginModule
diff --git a/webkit/glue/plugins/pepper_private.cc b/webkit/glue/plugins/pepper_private.cc
index 199dea7..f12e045 100644
--- a/webkit/glue/plugins/pepper_private.cc
+++ b/webkit/glue/plugins/pepper_private.cc
@@ -80,7 +80,7 @@ static const ResourceImageInfo kResourceImageMap[] = {
};
PP_Var GetLocalizedString(PP_Module module_id, PP_ResourceString string_id) {
- PluginModule* module = PluginModule::FromPPModule(module_id);
+ PluginModule* module = ResourceTracker::Get()->GetModule(module_id);
if (!module)
return PP_MakeUndefined();
@@ -105,7 +105,7 @@ PP_Resource GetResourceImage(PP_Module module_id, PP_ResourceImage image_id) {
SkBitmap* res_bitmap =
ResourceBundle::GetSharedInstance().GetBitmapNamed(res_id);
- PluginModule* module = PluginModule::FromPPModule(module_id);
+ PluginModule* module = ResourceTracker::Get()->GetModule(module_id);
if (!module)
return 0;
scoped_refptr<pepper::ImageData> image_data(new pepper::ImageData(module));
@@ -133,7 +133,7 @@ PP_Resource GetFontFileWithFallback(
const PP_FontDescription_Dev* description,
PP_PrivateFontCharset charset) {
#if defined(OS_LINUX)
- PluginModule* module = PluginModule::FromPPModule(module_id);
+ PluginModule* module = ResourceTracker::Get()->GetModule(module_id);
if (!module)
return 0;
diff --git a/webkit/glue/plugins/pepper_private2.cc b/webkit/glue/plugins/pepper_private2.cc
index 0efa13a..089eb37 100644
--- a/webkit/glue/plugins/pepper_private2.cc
+++ b/webkit/glue/plugins/pepper_private2.cc
@@ -12,7 +12,7 @@ namespace pepper {
namespace {
void SetInstanceAlwaysOnTop(PP_Instance pp_instance, bool on_top) {
- PluginInstance* instance = PluginInstance::FromPPInstance(pp_instance);
+ PluginInstance* instance = ResourceTracker::Get()->GetInstance(pp_instance);
if (!instance)
return;
instance->set_always_on_top(on_top);
diff --git a/webkit/glue/plugins/pepper_resource_tracker.cc b/webkit/glue/plugins/pepper_resource_tracker.cc
index 9ee54f8..2e18cd8 100644
--- a/webkit/glue/plugins/pepper_resource_tracker.cc
+++ b/webkit/glue/plugins/pepper_resource_tracker.cc
@@ -8,6 +8,7 @@
#include <set>
#include "base/logging.h"
+#include "base/rand_util.h"
#include "third_party/ppapi/c/pp_resource.h"
#include "webkit/glue/plugins/pepper_resource.h"
@@ -79,4 +80,78 @@ uint32 ResourceTracker::GetLiveObjectsForModule(PluginModule* module) const {
return count;
}
+PP_Instance ResourceTracker::AddInstance(PluginInstance* instance) {
+#ifndef NDEBUG
+ // Make sure we're not adding one more than once.
+ for (InstanceMap::const_iterator i = instance_map_.begin();
+ i != instance_map_.end(); ++i)
+ DCHECK(i->second != instance);
+#endif
+
+ // Use a random 64-bit number for the instance ID. This helps prevent some
+ // mischeif where you could misallocate resources if you gave a different
+ // instance ID.
+ //
+ // See also AddModule below.
+ //
+ // Need to make sure the random number isn't a duplicate or 0.
+ PP_Instance new_instance;
+ do {
+ new_instance = static_cast<PP_Instance>(base::RandUint64());
+ } while (!new_instance ||
+ instance_map_.find(new_instance) != instance_map_.end());
+ instance_map_[new_instance] = instance;
+ return new_instance;
+}
+
+void ResourceTracker::InstanceDeleted(PP_Instance instance) {
+ InstanceMap::iterator found = instance_map_.find(instance);
+ if (found == instance_map_.end()) {
+ NOTREACHED();
+ return;
+ }
+ instance_map_.erase(found);
+}
+
+PluginInstance* ResourceTracker::GetInstance(PP_Instance instance) {
+ InstanceMap::iterator found = instance_map_.find(instance);
+ if (found == instance_map_.end())
+ return NULL;
+ return found->second;
+}
+
+PP_Module ResourceTracker::AddModule(PluginModule* module) {
+#ifndef NDEBUG
+ // Make sure we're not adding one more than once.
+ for (ModuleMap::const_iterator i = module_map_.begin();
+ i != module_map_.end(); ++i)
+ DCHECK(i->second != module);
+#endif
+
+ // See AddInstance above.
+ PP_Module new_module;
+ do {
+ new_module = static_cast<PP_Module>(base::RandUint64());
+ } while (!new_module ||
+ module_map_.find(new_module) != module_map_.end());
+ module_map_[new_module] = module;
+ return new_module;
+}
+
+void ResourceTracker::ModuleDeleted(PP_Module module) {
+ ModuleMap::iterator found = module_map_.find(module);
+ if (found == module_map_.end()) {
+ NOTREACHED();
+ return;
+ }
+ module_map_.erase(found);
+}
+
+PluginModule* ResourceTracker::GetModule(PP_Module module) {
+ ModuleMap::iterator found = module_map_.find(module);
+ if (found == module_map_.end())
+ return NULL;
+ return found->second;
+}
+
} // namespace pepper
diff --git a/webkit/glue/plugins/pepper_resource_tracker.h b/webkit/glue/plugins/pepper_resource_tracker.h
index 59f02d2..5c27ebd 100644
--- a/webkit/glue/plugins/pepper_resource_tracker.h
+++ b/webkit/glue/plugins/pepper_resource_tracker.h
@@ -5,18 +5,22 @@
#ifndef WEBKIT_GLUE_PLUGINS_PEPPER_RESOURCE_TRACKER_H_
#define WEBKIT_GLUE_PLUGINS_PEPPER_RESOURCE_TRACKER_H_
+#include <map>
#include <utility>
#include "base/basictypes.h"
#include "base/hash_tables.h"
#include "base/ref_counted.h"
#include "base/singleton.h"
+#include "third_party/ppapi/c/pp_instance.h"
+#include "third_party/ppapi/c/pp_module.h"
#include "third_party/ppapi/c/pp_resource.h"
typedef struct NPObject NPObject;
namespace pepper {
+class PluginInstance;
class PluginModule;
class Resource;
@@ -31,6 +35,8 @@ class ResourceTracker {
return Singleton<ResourceTracker>::get();
}
+ // PP_Resources --------------------------------------------------------------
+
// The returned pointer will be NULL if there is no resource. Note that this
// return value is a scoped_refptr so that we ensure the resource is valid
// from the point of the lookup to the point that the calling code needs it.
@@ -48,6 +54,34 @@ class ResourceTracker {
// This is slow, use only for testing.
uint32 GetLiveObjectsForModule(PluginModule* module) const;
+ // PP_Modules ----------------------------------------------------------------
+
+ // Adds a new plugin module to the list of tracked module, and returns a new
+ // module handle to identify it.
+ PP_Module AddModule(PluginModule* module);
+
+ // Called when a plugin modulde was deleted and should no longer be tracked.
+ // The given handle should be one generated by AddModule.
+ void ModuleDeleted(PP_Module module);
+
+ // Returns a pointer to the plugin modulde object associated with the given
+ // modulde handle. The return value will be NULL if the handle is invalid.
+ PluginModule* GetModule(PP_Module module);
+
+ // PP_Instances --------------------------------------------------------------
+
+ // Adds a new plugin instance to the list of tracked instances, and returns a
+ // new instance handle to identify it.
+ PP_Instance AddInstance(PluginInstance* instance);
+
+ // Called when a plugin instance was deleted and should no longer be tracked.
+ // The given handle should be one generated by AddInstance.
+ void InstanceDeleted(PP_Instance instance);
+
+ // Returns a pointer to the plugin instance object associated with the given
+ // instance handle. The return value will be NULL if the handle is invalid.
+ PluginInstance* GetInstance(PP_Instance instance);
+
private:
friend struct DefaultSingletonTraits<ResourceTracker>;
friend class Resource;
@@ -74,6 +108,16 @@ class ResourceTracker {
typedef base::hash_map<PP_Resource, ResourceAndRefCount> ResourceMap;
ResourceMap live_resources_;
+ // Tracks all live instances. The pointers are non-owning, the PluginInstance
+ // destructor will notify us when the instance is deleted.
+ typedef std::map<PP_Instance, PluginInstance*> InstanceMap;
+ InstanceMap instance_map_;
+
+ // Tracks all live modules. The pointers are non-owning, the PluginModule
+ // destructor will notify us when the module is deleted.
+ typedef std::map<PP_Module, PluginModule*> ModuleMap;
+ ModuleMap module_map_;
+
DISALLOW_COPY_AND_ASSIGN(ResourceTracker);
};
diff --git a/webkit/glue/plugins/pepper_scrollbar.cc b/webkit/glue/plugins/pepper_scrollbar.cc
index a8943d2..c265851 100644
--- a/webkit/glue/plugins/pepper_scrollbar.cc
+++ b/webkit/glue/plugins/pepper_scrollbar.cc
@@ -31,7 +31,7 @@ namespace pepper {
namespace {
PP_Resource Create(PP_Instance instance_id, bool vertical) {
- PluginInstance* instance = PluginInstance::FromPPInstance(instance_id);
+ PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id);
if (!instance)
return 0;
@@ -196,7 +196,7 @@ void Scrollbar::valueChanged(WebKit::WebScrollbar* scrollbar) {
return;
ScopedResourceId resource(this);
ppp_scrollbar->ValueChanged(
- instance()->GetPPInstance(), resource.id, scrollbar_->value());
+ instance()->pp_instance(), resource.id, scrollbar_->value());
}
void Scrollbar::invalidateScrollbarRect(WebKit::WebScrollbar* scrollbar,
diff --git a/webkit/glue/plugins/pepper_url_loader.cc b/webkit/glue/plugins/pepper_url_loader.cc
index 4169c00..5e789f8 100644
--- a/webkit/glue/plugins/pepper_url_loader.cc
+++ b/webkit/glue/plugins/pepper_url_loader.cc
@@ -40,12 +40,11 @@ namespace pepper {
namespace {
PP_Resource Create(PP_Instance instance_id) {
- PluginInstance* instance = PluginInstance::FromPPInstance(instance_id);
+ PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id);
if (!instance)
return 0;
URLLoader* loader = new URLLoader(instance);
-
return loader->GetReference();
}
diff --git a/webkit/glue/plugins/pepper_url_request_info.cc b/webkit/glue/plugins/pepper_url_request_info.cc
index 21e17ea..45ae2d6 100644
--- a/webkit/glue/plugins/pepper_url_request_info.cc
+++ b/webkit/glue/plugins/pepper_url_request_info.cc
@@ -47,7 +47,7 @@ bool IsIgnoredRequestHeader(const std::string& name) {
}
PP_Resource Create(PP_Module module_id) {
- PluginModule* module = PluginModule::FromPPModule(module_id);
+ PluginModule* module = ResourceTracker::Get()->GetModule(module_id);
if (!module)
return 0;
diff --git a/webkit/glue/plugins/pepper_url_util.cc b/webkit/glue/plugins/pepper_url_util.cc
index 3f9a54f..a182b92 100644
--- a/webkit/glue/plugins/pepper_url_util.cc
+++ b/webkit/glue/plugins/pepper_url_util.cc
@@ -60,7 +60,7 @@ PP_Var GenerateUrlReturn(PluginModule* module, const GURL& url,
// unchanged.
bool SecurityOriginForInstance(PP_Instance instance_id,
WebKit::WebSecurityOrigin* security_origin) {
- PluginInstance* instance = PluginInstance::FromPPInstance(instance_id);
+ PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id);
if (!instance)
return false;
@@ -100,7 +100,7 @@ PP_Var ResolveRelativeToUrl(PP_Var base_url,
PP_Var ResolveRelativeToDocument(PP_Instance instance_id,
PP_Var relative,
PP_UrlComponents_Dev* components) {
- PluginInstance* instance = PluginInstance::FromPPInstance(instance_id);
+ PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id);
if (!instance)
return PP_MakeNull();
diff --git a/webkit/glue/plugins/pepper_var.cc b/webkit/glue/plugins/pepper_var.cc
index c83d443..6daece9 100644
--- a/webkit/glue/plugins/pepper_var.cc
+++ b/webkit/glue/plugins/pepper_var.cc
@@ -157,7 +157,7 @@ class ObjectAccessorWithIdentifierTryCatch : public ObjectAccessorTryCatch {
// PPB_Var methods -------------------------------------------------------------
PP_Var VarFromUtf8(PP_Module module_id, const char* data, uint32_t len) {
- PluginModule* module = PluginModule::FromPPModule(module_id);
+ PluginModule* module = ResourceTracker::Get()->GetModule(module_id);
if (!module)
return PP_MakeNull();
return StringVar::StringToPPVar(module, data, len);
@@ -381,7 +381,7 @@ bool IsInstanceOfDeprecated(PP_Var var,
PP_Var CreateObjectDeprecated(PP_Module module_id,
const PPP_Class_Deprecated* ppp_class,
void* ppp_class_data) {
- PluginModule* module = PluginModule::FromPPModule(module_id);
+ PluginModule* module = ResourceTracker::Get()->GetModule(module_id);
if (!module)
return PP_MakeNull();
return PluginObject::Create(module, ppp_class, ppp_class_data);
diff --git a/webkit/glue/plugins/pepper_video_decoder.cc b/webkit/glue/plugins/pepper_video_decoder.cc
index ed572b3..3ca0ab2 100644
--- a/webkit/glue/plugins/pepper_video_decoder.cc
+++ b/webkit/glue/plugins/pepper_video_decoder.cc
@@ -22,7 +22,7 @@ bool GetConfig(PP_Instance instance_id,
PP_VideoConfig_Dev* configs,
int32_t config_size,
int32_t *num_config) {
- PluginInstance* instance = PluginInstance::FromPPInstance(instance_id);
+ PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id);
*num_config = 0;
if (!instance)
return false;
@@ -40,7 +40,7 @@ bool GetConfig(PP_Instance instance_id,
PP_Resource Create(PP_Instance instance_id,
const PP_VideoDecoderConfig_Dev* decoder_config) {
- PluginInstance* instance = PluginInstance::FromPPInstance(instance_id);
+ PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id);
if (!instance)
return 0;
diff --git a/webkit/glue/plugins/pepper_widget.cc b/webkit/glue/plugins/pepper_widget.cc
index 1ba5280..7002576 100644
--- a/webkit/glue/plugins/pepper_widget.cc
+++ b/webkit/glue/plugins/pepper_widget.cc
@@ -88,7 +88,7 @@ void Widget::Invalidate(const PP_Rect* dirty) {
if (!widget)
return;
ScopedResourceId resource(this);
- widget->Invalidate(instance_->GetPPInstance(), resource.id, dirty);
+ widget->Invalidate(instance_->pp_instance(), resource.id, dirty);
}
} // namespace pepper