OLD | NEW |
1 /** | 1 /** |
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
4 * (C) 2000 Stefan Schimanski (1Stein@gmx.de) | 4 * (C) 2000 Stefan Schimanski (1Stein@gmx.de) |
5 * Copyright (C) 2004, 2005, 2006 Apple Computer, Inc. | 5 * Copyright (C) 2004, 2005, 2006 Apple Computer, Inc. |
6 * | 6 * |
7 * This library is free software; you can redistribute it and/or | 7 * This library is free software; you can redistribute it and/or |
8 * modify it under the terms of the GNU Library General Public | 8 * modify it under the terms of the GNU Library General Public |
9 * License as published by the Free Software Foundation; either | 9 * License as published by the Free Software Foundation; either |
10 * version 2 of the License, or (at your option) any later version. | 10 * version 2 of the License, or (at your option) any later version. |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 should_prefer_plug_ins_for_images_(prefer_plug_ins_for_images_option == | 86 should_prefer_plug_ins_for_images_(prefer_plug_ins_for_images_option == |
87 kShouldPreferPlugInsForImages) {} | 87 kShouldPreferPlugInsForImages) {} |
88 | 88 |
89 HTMLPlugInElement::~HTMLPlugInElement() { | 89 HTMLPlugInElement::~HTMLPlugInElement() { |
90 DCHECK(plugin_wrapper_.IsEmpty()); // cleared in detachLayoutTree() | 90 DCHECK(plugin_wrapper_.IsEmpty()); // cleared in detachLayoutTree() |
91 DCHECK(!is_delaying_load_event_); | 91 DCHECK(!is_delaying_load_event_); |
92 } | 92 } |
93 | 93 |
94 DEFINE_TRACE(HTMLPlugInElement) { | 94 DEFINE_TRACE(HTMLPlugInElement) { |
95 visitor->Trace(image_loader_); | 95 visitor->Trace(image_loader_); |
96 visitor->Trace(plugin_); | |
97 visitor->Trace(persisted_plugin_); | 96 visitor->Trace(persisted_plugin_); |
98 HTMLFrameOwnerElement::Trace(visitor); | 97 HTMLFrameOwnerElement::Trace(visitor); |
99 } | 98 } |
100 | 99 |
101 void HTMLPlugInElement::SetPlugin(PluginView* plugin) { | |
102 if (plugin == plugin_) | |
103 return; | |
104 | |
105 // Remove and dispose the old plugin if we had one. | |
106 if (plugin_) { | |
107 GetDocument().View()->RemovePlugin(plugin_); | |
108 DisposeFrameOrPluginSoon(plugin_); | |
109 } | |
110 plugin_ = plugin; | |
111 | |
112 // TODO(joelhockey): I copied the rest of this method from | |
113 // HTMLFrameOwnerElement. There may be parts that can be removed | |
114 // such as the layoutPartItem.isNull check and DCHECKs. | |
115 // Once widget tree is removed (FrameView::m_children), try to unify | |
116 // this code with HTMLFrameOwnerElement::setWidget. | |
117 LayoutPart* layout_part = ToLayoutPart(GetLayoutObject()); | |
118 LayoutPartItem layout_part_item = LayoutPartItem(layout_part); | |
119 if (layout_part_item.IsNull()) | |
120 return; | |
121 | |
122 // Update layout and frame with new plugin. | |
123 if (plugin_) { | |
124 layout_part_item.UpdateOnWidgetChange(); | |
125 | |
126 DCHECK_EQ(GetDocument().View(), layout_part_item.GetFrameView()); | |
127 DCHECK(layout_part_item.GetFrameView()); | |
128 GetDocument().View()->AddPlugin(plugin); | |
129 } | |
130 | |
131 // Apparently accessibility objects might have been modified if plugin | |
132 // was removed. | |
133 if (AXObjectCache* cache = GetDocument().ExistingAXObjectCache()) | |
134 cache->ChildrenChanged(layout_part); | |
135 } | |
136 | |
137 PluginView* HTMLPlugInElement::ReleasePlugin() { | |
138 if (!plugin_) | |
139 return nullptr; | |
140 GetDocument().View()->RemovePlugin(plugin_); | |
141 LayoutPart* layout_part = ToLayoutPart(GetLayoutObject()); | |
142 if (layout_part) { | |
143 if (AXObjectCache* cache = GetDocument().ExistingAXObjectCache()) | |
144 cache->ChildrenChanged(layout_part); | |
145 } | |
146 return plugin_.Release(); | |
147 } | |
148 | |
149 void HTMLPlugInElement::SetPersistedPlugin(PluginView* plugin) { | 100 void HTMLPlugInElement::SetPersistedPlugin(PluginView* plugin) { |
150 if (persisted_plugin_ == plugin) | 101 if (persisted_plugin_ == plugin) |
151 return; | 102 return; |
152 if (persisted_plugin_) { | 103 if (persisted_plugin_) { |
153 persisted_plugin_->Hide(); | 104 persisted_plugin_->Hide(); |
154 DisposeFrameOrPluginSoon(persisted_plugin_.Release()); | 105 DisposeFrameOrPluginSoon(persisted_plugin_.Release()); |
155 } | 106 } |
156 persisted_plugin_ = plugin; | 107 persisted_plugin_ = plugin; |
157 } | 108 } |
158 | 109 |
159 void HTMLPlugInElement::SetFocused(bool focused, WebFocusType focus_type) { | 110 void HTMLPlugInElement::SetFocused(bool focused, WebFocusType focus_type) { |
160 if (plugin_) | 111 PluginView* plugin = OwnedPlugin(); |
161 plugin_->SetFocused(focused, focus_type); | 112 if (plugin) |
| 113 plugin->SetFocused(focused, focus_type); |
162 HTMLFrameOwnerElement::SetFocused(focused, focus_type); | 114 HTMLFrameOwnerElement::SetFocused(focused, focus_type); |
163 } | 115 } |
164 | 116 |
165 bool HTMLPlugInElement::RequestObjectInternal( | 117 bool HTMLPlugInElement::RequestObjectInternal( |
166 const String& url, | 118 const String& url, |
167 const String& mime_type, | 119 const String& mime_type, |
168 const Vector<String>& param_names, | 120 const Vector<String>& param_names, |
169 const Vector<String>& param_values) { | 121 const Vector<String>& param_values) { |
170 if (url.IsEmpty() && mime_type.IsEmpty()) | 122 if (url.IsEmpty() && mime_type.IsEmpty()) |
171 return false; | 123 return false; |
(...skipping 29 matching lines...) Expand all Loading... |
201 | 153 |
202 bool HTMLPlugInElement::WillRespondToMouseClickEvents() { | 154 bool HTMLPlugInElement::WillRespondToMouseClickEvents() { |
203 if (IsDisabledFormControl()) | 155 if (IsDisabledFormControl()) |
204 return false; | 156 return false; |
205 LayoutObject* r = GetLayoutObject(); | 157 LayoutObject* r = GetLayoutObject(); |
206 return r && (r->IsEmbeddedObject() || r->IsLayoutPart()); | 158 return r && (r->IsEmbeddedObject() || r->IsLayoutPart()); |
207 } | 159 } |
208 | 160 |
209 void HTMLPlugInElement::RemoveAllEventListeners() { | 161 void HTMLPlugInElement::RemoveAllEventListeners() { |
210 HTMLFrameOwnerElement::RemoveAllEventListeners(); | 162 HTMLFrameOwnerElement::RemoveAllEventListeners(); |
211 if (plugin_) { | 163 PluginView* plugin = OwnedPlugin(); |
212 plugin_->EventListenersRemoved(); | 164 if (plugin) |
213 } | 165 plugin->EventListenersRemoved(); |
214 } | 166 } |
215 | 167 |
216 void HTMLPlugInElement::DidMoveToNewDocument(Document& old_document) { | 168 void HTMLPlugInElement::DidMoveToNewDocument(Document& old_document) { |
217 if (image_loader_) | 169 if (image_loader_) |
218 image_loader_->ElementDidMoveToNewDocument(); | 170 image_loader_->ElementDidMoveToNewDocument(); |
219 HTMLFrameOwnerElement::DidMoveToNewDocument(old_document); | 171 HTMLFrameOwnerElement::DidMoveToNewDocument(old_document); |
220 } | 172 } |
221 | 173 |
222 void HTMLPlugInElement::AttachLayoutTree(const AttachContext& context) { | 174 void HTMLPlugInElement::AttachLayoutTree(const AttachContext& context) { |
223 HTMLFrameOwnerElement::AttachLayoutTree(context); | 175 HTMLFrameOwnerElement::AttachLayoutTree(context); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 | 254 |
303 param_names.push_back("type"); | 255 param_names.push_back("type"); |
304 param_values.push_back(service_type_); | 256 param_values.push_back(service_type_); |
305 | 257 |
306 bool use_fallback = false; | 258 bool use_fallback = false; |
307 LoadPlugin(url, service_type_, param_names, param_values, use_fallback, | 259 LoadPlugin(url, service_type_, param_names, param_values, use_fallback, |
308 false); | 260 false); |
309 } | 261 } |
310 | 262 |
311 bool HTMLPlugInElement::ShouldAccelerate() const { | 263 bool HTMLPlugInElement::ShouldAccelerate() const { |
312 return plugin_ && plugin_->PlatformLayer(); | 264 PluginView* plugin = OwnedPlugin(); |
| 265 return plugin && plugin->PlatformLayer(); |
313 } | 266 } |
314 | 267 |
315 void HTMLPlugInElement::DetachLayoutTree(const AttachContext& context) { | 268 void HTMLPlugInElement::DetachLayoutTree(const AttachContext& context) { |
316 // Update the FrameViewBase the next time we attach (detaching destroys the | 269 // Update the FrameViewBase the next time we attach (detaching destroys the |
317 // plugin). | 270 // plugin). |
318 // FIXME: None of this "needsPluginUpdate" related code looks right. | 271 // FIXME: None of this "needsPluginUpdate" related code looks right. |
319 if (GetLayoutObject() && !UseFallbackContent()) | 272 if (GetLayoutObject() && !UseFallbackContent()) |
320 SetNeedsPluginUpdate(true); | 273 SetNeedsPluginUpdate(true); |
321 | 274 |
322 if (is_delaying_load_event_) { | 275 if (is_delaying_load_event_) { |
323 is_delaying_load_event_ = false; | 276 is_delaying_load_event_ = false; |
324 GetDocument().DecrementLoadEventDelayCount(); | 277 GetDocument().DecrementLoadEventDelayCount(); |
325 } | 278 } |
326 | 279 |
327 // Only try to persist a plugin we actually own. | 280 // Only try to persist a plugin we actually own. |
328 if (plugin_ && context.performing_reattach) { | 281 PluginView* plugin = OwnedPlugin(); |
329 SetPersistedPlugin(ReleasePlugin()); | 282 if (plugin && context.performing_reattach) { |
| 283 SetPersistedPlugin(ToPluginView(ReleaseWidget())); |
330 } else { | 284 } else { |
331 // Clear the plugin; will trigger disposal of it with Oilpan. | 285 // Clear the plugin; will trigger disposal of it with Oilpan. |
332 SetPlugin(nullptr); | 286 SetWidget(nullptr); |
333 } | 287 } |
334 | 288 |
335 ResetInstance(); | 289 ResetInstance(); |
336 | 290 |
337 HTMLFrameOwnerElement::DetachLayoutTree(context); | 291 HTMLFrameOwnerElement::DetachLayoutTree(context); |
338 } | 292 } |
339 | 293 |
340 LayoutObject* HTMLPlugInElement::CreateLayoutObject( | 294 LayoutObject* HTMLPlugInElement::CreateLayoutObject( |
341 const ComputedStyle& style) { | 295 const ComputedStyle& style) { |
342 // Fallback content breaks the DOM->layoutObject class relationship of this | 296 // Fallback content breaks the DOM->layoutObject class relationship of this |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 return v8::Local<v8::Object>(); | 329 return v8::Local<v8::Object>(); |
376 | 330 |
377 // If the host dynamically turns off JavaScript (or Java) we will still | 331 // If the host dynamically turns off JavaScript (or Java) we will still |
378 // return the cached allocated Bindings::Instance. Not supporting this | 332 // return the cached allocated Bindings::Instance. Not supporting this |
379 // edge-case is OK. | 333 // edge-case is OK. |
380 v8::Isolate* isolate = V8PerIsolateData::MainThreadIsolate(); | 334 v8::Isolate* isolate = V8PerIsolateData::MainThreadIsolate(); |
381 if (plugin_wrapper_.IsEmpty()) { | 335 if (plugin_wrapper_.IsEmpty()) { |
382 PluginView* plugin; | 336 PluginView* plugin; |
383 | 337 |
384 if (persisted_plugin_) | 338 if (persisted_plugin_) |
385 plugin = persisted_plugin_.Get(); | 339 plugin = persisted_plugin_; |
386 else | 340 else |
387 plugin = PluginWidget(); | 341 plugin = PluginWidget(); |
388 | 342 |
389 if (plugin) | 343 if (plugin) |
390 plugin_wrapper_.Reset(isolate, plugin->ScriptableObject(isolate)); | 344 plugin_wrapper_.Reset(isolate, plugin->ScriptableObject(isolate)); |
391 } | 345 } |
392 return plugin_wrapper_.Get(isolate); | 346 return plugin_wrapper_.Get(isolate); |
393 } | 347 } |
394 | 348 |
395 PluginView* HTMLPlugInElement::PluginWidget() const { | 349 PluginView* HTMLPlugInElement::PluginWidget() const { |
396 if (LayoutPart* layout_part = LayoutPartForJSBindings()) | 350 if (LayoutPart* layout_part = LayoutPartForJSBindings()) |
397 return layout_part->Plugin(); | 351 return layout_part->Plugin(); |
398 return nullptr; | 352 return nullptr; |
399 } | 353 } |
400 | 354 |
401 PluginView* HTMLPlugInElement::Plugin() const { | 355 PluginView* HTMLPlugInElement::OwnedPlugin() const { |
402 return plugin_.Get(); | 356 FrameOrPlugin* frame_or_plugin = OwnedWidget(); |
| 357 if (frame_or_plugin && frame_or_plugin->IsPluginView()) |
| 358 return ToPluginView(frame_or_plugin); |
| 359 return nullptr; |
403 } | 360 } |
404 | 361 |
405 bool HTMLPlugInElement::IsPresentationAttribute( | 362 bool HTMLPlugInElement::IsPresentationAttribute( |
406 const QualifiedName& name) const { | 363 const QualifiedName& name) const { |
407 if (name == widthAttr || name == heightAttr || name == vspaceAttr || | 364 if (name == widthAttr || name == heightAttr || name == vspaceAttr || |
408 name == hspaceAttr || name == alignAttr) | 365 name == hspaceAttr || name == alignAttr) |
409 return true; | 366 return true; |
410 return HTMLFrameOwnerElement::IsPresentationAttribute(name); | 367 return HTMLFrameOwnerElement::IsPresentationAttribute(name); |
411 } | 368 } |
412 | 369 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
444 // code in EventHandler; these code paths should be united. | 401 // code in EventHandler; these code paths should be united. |
445 | 402 |
446 LayoutObject* r = GetLayoutObject(); | 403 LayoutObject* r = GetLayoutObject(); |
447 if (!r || !r->IsLayoutPart()) | 404 if (!r || !r->IsLayoutPart()) |
448 return; | 405 return; |
449 if (r->IsEmbeddedObject()) { | 406 if (r->IsEmbeddedObject()) { |
450 if (LayoutEmbeddedItem(ToLayoutEmbeddedObject(r)) | 407 if (LayoutEmbeddedItem(ToLayoutEmbeddedObject(r)) |
451 .ShowsUnavailablePluginIndicator()) | 408 .ShowsUnavailablePluginIndicator()) |
452 return; | 409 return; |
453 } | 410 } |
454 if (!plugin_) | 411 PluginView* plugin = OwnedPlugin(); |
| 412 if (!plugin) |
455 return; | 413 return; |
456 plugin_->HandleEvent(event); | 414 plugin->HandleEvent(event); |
457 if (event->DefaultHandled()) | 415 if (event->DefaultHandled()) |
458 return; | 416 return; |
459 HTMLFrameOwnerElement::DefaultEventHandler(event); | 417 HTMLFrameOwnerElement::DefaultEventHandler(event); |
460 } | 418 } |
461 | 419 |
462 LayoutPart* HTMLPlugInElement::LayoutPartForJSBindings() const { | 420 LayoutPart* HTMLPlugInElement::LayoutPartForJSBindings() const { |
463 // Needs to load the plugin immediatedly because this function is called | 421 // Needs to load the plugin immediatedly because this function is called |
464 // when JavaScript code accesses the plugin. | 422 // when JavaScript code accesses the plugin. |
465 // FIXME: Check if dispatching events here is safe. | 423 // FIXME: Check if dispatching events here is safe. |
466 GetDocument().UpdateStyleAndLayoutIgnorePendingStylesheets( | 424 GetDocument().UpdateStyleAndLayoutIgnorePendingStylesheets( |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
581 LayoutEmbeddedItem layout_item = GetLayoutEmbeddedItem(); | 539 LayoutEmbeddedItem layout_item = GetLayoutEmbeddedItem(); |
582 // FIXME: This code should not depend on layoutObject! | 540 // FIXME: This code should not depend on layoutObject! |
583 if ((layout_item.IsNull() && require_layout_object) || use_fallback) | 541 if ((layout_item.IsNull() && require_layout_object) || use_fallback) |
584 return false; | 542 return false; |
585 | 543 |
586 VLOG(1) << this << " Plugin URL: " << url_; | 544 VLOG(1) << this << " Plugin URL: " << url_; |
587 VLOG(1) << "Loaded URL: " << url.GetString(); | 545 VLOG(1) << "Loaded URL: " << url.GetString(); |
588 loaded_url_ = url; | 546 loaded_url_ = url; |
589 | 547 |
590 if (persisted_plugin_) { | 548 if (persisted_plugin_) { |
591 SetPlugin(persisted_plugin_.Release()); | 549 SetWidget(persisted_plugin_.Release()); |
592 } else { | 550 } else { |
593 bool load_manually = | 551 bool load_manually = |
594 GetDocument().IsPluginDocument() && !GetDocument().ContainsPlugins(); | 552 GetDocument().IsPluginDocument() && !GetDocument().ContainsPlugins(); |
595 LocalFrameClient::DetachedPluginPolicy policy = | 553 LocalFrameClient::DetachedPluginPolicy policy = |
596 require_layout_object ? LocalFrameClient::kFailOnDetachedPlugin | 554 require_layout_object ? LocalFrameClient::kFailOnDetachedPlugin |
597 : LocalFrameClient::kAllowDetachedPlugin; | 555 : LocalFrameClient::kAllowDetachedPlugin; |
598 PluginView* plugin = frame->Loader().Client()->CreatePlugin( | 556 PluginView* plugin = frame->Loader().Client()->CreatePlugin( |
599 this, url, param_names, param_values, mime_type, load_manually, policy); | 557 this, url, param_names, param_values, mime_type, load_manually, policy); |
600 if (!plugin) { | 558 if (!plugin) { |
601 if (!layout_item.IsNull() && | 559 if (!layout_item.IsNull() && |
602 !layout_item.ShowsUnavailablePluginIndicator()) { | 560 !layout_item.ShowsUnavailablePluginIndicator()) { |
603 plugin_is_available_ = false; | 561 plugin_is_available_ = false; |
604 layout_item.SetPluginAvailability(LayoutEmbeddedObject::kPluginMissing); | 562 layout_item.SetPluginAvailability(LayoutEmbeddedObject::kPluginMissing); |
605 } | 563 } |
606 return false; | 564 return false; |
607 } | 565 } |
608 | 566 |
609 if (!layout_item.IsNull()) | 567 if (!layout_item.IsNull()) |
610 SetPlugin(plugin); | 568 SetWidget(plugin); |
611 else | 569 else |
612 SetPersistedPlugin(plugin); | 570 SetPersistedPlugin(plugin); |
613 } | 571 } |
614 | 572 |
615 GetDocument().SetContainsPlugins(); | 573 GetDocument().SetContainsPlugins(); |
616 // TODO(esprehn): WebPluginContainerImpl::setWebLayer also schedules a | 574 // TODO(esprehn): WebPluginContainerImpl::setWebLayer also schedules a |
617 // compositing update, do we need both? | 575 // compositing update, do we need both? |
618 SetNeedsCompositingUpdate(); | 576 SetNeedsCompositingUpdate(); |
619 // Make sure any input event handlers introduced by the plugin are taken into | 577 // Make sure any input event handlers introduced by the plugin are taken into |
620 // account. | 578 // account. |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
714 | 672 |
715 void HTMLPlugInElement::LazyReattachIfNeeded() { | 673 void HTMLPlugInElement::LazyReattachIfNeeded() { |
716 if (!UseFallbackContent() && NeedsPluginUpdate() && GetLayoutObject() && | 674 if (!UseFallbackContent() && NeedsPluginUpdate() && GetLayoutObject() && |
717 !IsImageType()) { | 675 !IsImageType()) { |
718 LazyReattachIfAttached(); | 676 LazyReattachIfAttached(); |
719 SetPersistedPlugin(nullptr); | 677 SetPersistedPlugin(nullptr); |
720 } | 678 } |
721 } | 679 } |
722 | 680 |
723 } // namespace blink | 681 } // namespace blink |
OLD | NEW |