OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/plugins/renderer/loadable_plugin_placeholder.h" | 5 #include "components/plugins/renderer/loadable_plugin_placeholder.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 if (!new_plugin) | 97 if (!new_plugin) |
98 return; | 98 return; |
99 blink::WebPluginContainer* container = plugin()->container(); | 99 blink::WebPluginContainer* container = plugin()->container(); |
100 // This can occur if the container has been destroyed. | 100 // This can occur if the container has been destroyed. |
101 if (!container) { | 101 if (!container) { |
102 new_plugin->destroy(); | 102 new_plugin->destroy(); |
103 return; | 103 return; |
104 } | 104 } |
105 | 105 |
106 container->setPlugin(new_plugin); | 106 container->setPlugin(new_plugin); |
107 // Save the element in case the plugin is removed from the page during | |
108 // initialization. | |
109 blink::WebElement element = container->element(); | |
110 bool plugin_needs_initialization = | 107 bool plugin_needs_initialization = |
111 !premade_throttler_ || new_plugin != premade_throttler_->GetWebPlugin(); | 108 !premade_throttler_ || new_plugin != premade_throttler_->GetWebPlugin(); |
112 if (plugin_needs_initialization && !new_plugin->initialize(container)) { | 109 if (plugin_needs_initialization && !new_plugin->initialize(container)) { |
113 if (new_plugin->container()) { | 110 if (new_plugin->container()) { |
114 // Since the we couldn't initialize the new plugin, but the container | 111 // Since the we couldn't initialize the new plugin, but the container |
115 // still exists, restore the placeholder and destroy the new plugin. | 112 // still exists, restore the placeholder and destroy the new plugin. |
116 container->setPlugin(plugin()); | 113 container->setPlugin(plugin()); |
117 new_plugin->destroy(); | 114 new_plugin->destroy(); |
| 115 } else { |
| 116 // The container has been destroyed, along with the new plugin. Destroy |
| 117 // our placeholder plugin also. |
| 118 plugin()->destroy(); |
118 } | 119 } |
119 return; | 120 return; |
120 } | 121 } |
121 | 122 |
122 // The plugin has been removed from the page. Destroy the old plugin. We | |
123 // will be destroyed as soon as V8 garbage collects us. | |
124 if (!element.pluginContainer()) { | |
125 plugin()->destroy(); | |
126 return; | |
127 } | |
128 | |
129 // During initialization, the new plugin might have replaced itself in turn | 123 // During initialization, the new plugin might have replaced itself in turn |
130 // with another plugin. Make sure not to use the passed in |new_plugin| after | 124 // with another plugin. Make sure not to use the passed in |new_plugin| after |
131 // this point. | 125 // this point. |
132 new_plugin = container->plugin(); | 126 new_plugin = container->plugin(); |
133 | 127 |
134 plugin()->RestoreTitleText(); | 128 plugin()->RestoreTitleText(); |
135 container->invalidate(); | 129 container->invalidate(); |
136 container->reportGeometry(); | 130 container->reportGeometry(); |
137 plugin()->ReplayReceivedData(new_plugin); | 131 plugin()->ReplayReceivedData(new_plugin); |
138 plugin()->destroy(); | 132 plugin()->destroy(); |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 return identifier_; | 359 return identifier_; |
366 } | 360 } |
367 | 361 |
368 bool LoadablePluginPlaceholder::LoadingBlocked() const { | 362 bool LoadablePluginPlaceholder::LoadingBlocked() const { |
369 DCHECK(allow_loading_); | 363 DCHECK(allow_loading_); |
370 return is_blocked_for_tinyness_ || is_blocked_for_background_tab_ || | 364 return is_blocked_for_tinyness_ || is_blocked_for_background_tab_ || |
371 is_blocked_for_power_saver_poster_ || is_blocked_for_prerendering_; | 365 is_blocked_for_power_saver_poster_ || is_blocked_for_prerendering_; |
372 } | 366 } |
373 | 367 |
374 } // namespace plugins | 368 } // namespace plugins |
OLD | NEW |