OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/renderer/pepper_plugin_delegate_impl.h" | 5 #include "chrome/renderer/pepper_plugin_delegate_impl.h" |
6 | 6 |
7 #include "app/surface/transport_dib.h" | 7 #include "app/surface/transport_dib.h" |
8 #include "base/scoped_ptr.h" | 8 #include "base/scoped_ptr.h" |
| 9 #include "webkit/glue/plugins/pepper_plugin_instance.h" |
9 | 10 |
10 #if defined(OS_MACOSX) | 11 #if defined(OS_MACOSX) |
11 #include "chrome/common/render_messages.h" | 12 #include "chrome/common/render_messages.h" |
12 #include "chrome/renderer/render_thread.h" | 13 #include "chrome/renderer/render_thread.h" |
13 #endif | 14 #endif |
14 | 15 |
15 namespace { | 16 namespace { |
16 | 17 |
17 // Implements the Image2D using a TransportDIB. | 18 // Implements the Image2D using a TransportDIB. |
18 class PlatformImage2DImpl : public pepper::PluginDelegate::PlatformImage2D { | 19 class PlatformImage2DImpl : public pepper::PluginDelegate::PlatformImage2D { |
(...skipping 20 matching lines...) Expand all Loading... |
39 | 40 |
40 DISALLOW_COPY_AND_ASSIGN(PlatformImage2DImpl); | 41 DISALLOW_COPY_AND_ASSIGN(PlatformImage2DImpl); |
41 }; | 42 }; |
42 | 43 |
43 } // namespace | 44 } // namespace |
44 | 45 |
45 PepperPluginDelegateImpl::PepperPluginDelegateImpl(RenderView* render_view) | 46 PepperPluginDelegateImpl::PepperPluginDelegateImpl(RenderView* render_view) |
46 : render_view_(render_view) { | 47 : render_view_(render_view) { |
47 } | 48 } |
48 | 49 |
| 50 void PepperPluginDelegateImpl::ViewInitiatedPaint() { |
| 51 // Notify all of our instances that we started painting. This is used for |
| 52 // internal bookkeeping only, so we know that the set can not change under |
| 53 // us. |
| 54 for (std::set<pepper::PluginInstance*>::iterator i = |
| 55 active_instances_.begin(); |
| 56 i != active_instances_.end(); ++i) |
| 57 (*i)->ViewInitiatedPaint(); |
| 58 } |
| 59 |
| 60 void PepperPluginDelegateImpl::ViewFlushedPaint() { |
| 61 // Notify all instances that we painted. This will call into the plugin, and |
| 62 // we it may ask to close itself as a result. This will, in turn, modify our |
| 63 // set, possibly invalidating the iterator. So we iterate on a copy that |
| 64 // won't change out from under us. |
| 65 std::set<pepper::PluginInstance*> plugins = active_instances_; |
| 66 for (std::set<pepper::PluginInstance*>::iterator i = plugins.begin(); |
| 67 i != plugins.end(); ++i) { |
| 68 // The copy above makes sure our iterator is never invalid if some plugins |
| 69 // are destroyed. But some plugin may decide to close all of its views in |
| 70 // response to a paint in one of them, so we need to make sure each one is |
| 71 // still "current" before using it. |
| 72 // |
| 73 // It's possible that a plugin was destroyed, but another one was created |
| 74 // with the same address. In this case, we'll call ViewFlushedPaint on that |
| 75 // new plugin. But that's OK for this particular case since we're just |
| 76 // notifying all of our instances that the view flushed, and the new one is |
| 77 // one of our instances. |
| 78 // |
| 79 // What about the case where a new one is created in a callback at a new |
| 80 // address and we don't issue the callback? We're still OK since this |
| 81 // callback is used for flush callbacks and we could not have possibly |
| 82 // started a new paint (ViewInitiatedPaint) for the new plugin while |
| 83 // processing a previous paint for an existing one. |
| 84 if (active_instances_.find(*i) != active_instances_.end()) |
| 85 (*i)->ViewFlushedPaint(); |
| 86 } |
| 87 } |
| 88 |
| 89 void PepperPluginDelegateImpl::InstanceCreated( |
| 90 pepper::PluginInstance* instance) { |
| 91 active_instances_.insert(instance); |
| 92 } |
| 93 |
| 94 void PepperPluginDelegateImpl::InstanceDeleted( |
| 95 pepper::PluginInstance* instance) { |
| 96 active_instances_.erase(instance); |
| 97 } |
| 98 |
49 pepper::PluginDelegate::PlatformImage2D* | 99 pepper::PluginDelegate::PlatformImage2D* |
50 PepperPluginDelegateImpl::CreateImage2D(int width, int height) { | 100 PepperPluginDelegateImpl::CreateImage2D(int width, int height) { |
51 uint32 buffer_size = width * height * 4; | 101 uint32 buffer_size = width * height * 4; |
52 | 102 |
53 // Allocate the transport DIB and the PlatformCanvas pointing to it. | 103 // Allocate the transport DIB and the PlatformCanvas pointing to it. |
54 #if defined(OS_MACOSX) | 104 #if defined(OS_MACOSX) |
55 // On the Mac, shared memory has to be created in the browser in order to | 105 // On the Mac, shared memory has to be created in the browser in order to |
56 // work in the sandbox. Do this by sending a message to the browser | 106 // work in the sandbox. Do this by sending a message to the browser |
57 // requesting a TransportDIB (see also | 107 // requesting a TransportDIB (see also |
58 // chrome/renderer/webplugin_delegate_proxy.cc, method | 108 // chrome/renderer/webplugin_delegate_proxy.cc, method |
(...skipping 15 matching lines...) Expand all Loading... |
74 TransportDIB* dib = TransportDIB::Map(dib_handle); | 124 TransportDIB* dib = TransportDIB::Map(dib_handle); |
75 #else | 125 #else |
76 static int next_dib_id = 0; | 126 static int next_dib_id = 0; |
77 TransportDIB* dib = TransportDIB::Create(buffer_size, next_dib_id++); | 127 TransportDIB* dib = TransportDIB::Create(buffer_size, next_dib_id++); |
78 if (!dib) | 128 if (!dib) |
79 return NULL; | 129 return NULL; |
80 #endif | 130 #endif |
81 | 131 |
82 return new PlatformImage2DImpl(width, height, dib); | 132 return new PlatformImage2DImpl(width, height, dib); |
83 } | 133 } |
OLD | NEW |