| 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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 } | 111 } |
| 112 | 112 |
| 113 void HTMLPlugInElement::SetFocused(bool focused, WebFocusType focus_type) { | 113 void HTMLPlugInElement::SetFocused(bool focused, WebFocusType focus_type) { |
| 114 PluginView* plugin = OwnedPlugin(); | 114 PluginView* plugin = OwnedPlugin(); |
| 115 if (plugin) | 115 if (plugin) |
| 116 plugin->SetFocused(focused, focus_type); | 116 plugin->SetFocused(focused, focus_type); |
| 117 HTMLFrameOwnerElement::SetFocused(focused, focus_type); | 117 HTMLFrameOwnerElement::SetFocused(focused, focus_type); |
| 118 } | 118 } |
| 119 | 119 |
| 120 bool HTMLPlugInElement::RequestObjectInternal( | 120 bool HTMLPlugInElement::RequestObjectInternal( |
| 121 const String& url, | |
| 122 const String& mime_type, | |
| 123 const Vector<String>& param_names, | 121 const Vector<String>& param_names, |
| 124 const Vector<String>& param_values) { | 122 const Vector<String>& param_values) { |
| 125 if (url.IsEmpty() && mime_type.IsEmpty()) | 123 if (url_.IsEmpty() && service_type_.IsEmpty()) |
| 126 return false; | 124 return false; |
| 127 | 125 |
| 128 if (ProtocolIsJavaScript(url)) | 126 if (ProtocolIsJavaScript(url_)) |
| 129 return false; | 127 return false; |
| 130 | 128 |
| 131 KURL completed_url = url.IsEmpty() ? KURL() : GetDocument().CompleteURL(url); | 129 KURL completed_url = |
| 132 if (!AllowedToLoadObject(completed_url, mime_type)) | 130 url_.IsEmpty() ? KURL() : GetDocument().CompleteURL(url_); |
| 131 if (!AllowedToLoadObject(completed_url, service_type_)) |
| 133 return false; | 132 return false; |
| 134 | 133 |
| 135 bool use_fallback; | 134 ObjectContentType object_type = GetObjectContentType(); |
| 136 if (!ShouldUsePlugin(completed_url, mime_type, HasFallbackContent(), | 135 if (object_type == ObjectContentType::kFrame || |
| 137 use_fallback)) { | 136 object_type == ObjectContentType::kImage) { |
| 138 // If the plugin element already contains a subframe, | 137 // If the plugin element already contains a subframe, |
| 139 // loadOrRedirectSubframe will re-use it. Otherwise, it will create a | 138 // loadOrRedirectSubframe will re-use it. Otherwise, it will create a |
| 140 // new frame and set it as the LayoutEmbeddedContent's EmbeddedContentView, | 139 // new frame and set it as the LayoutEmbeddedContent's EmbeddedContentView, |
| 141 // causing what was previously in the EmbeddedContentView to be torn down. | 140 // causing what was previously in the EmbeddedContentView to be torn down. |
| 142 return LoadOrRedirectSubframe(completed_url, GetNameAttribute(), true); | 141 return LoadOrRedirectSubframe(completed_url, GetNameAttribute(), true); |
| 143 } | 142 } |
| 144 | 143 |
| 145 return LoadPlugin(completed_url, mime_type, param_names, param_values, | 144 // If an object's content can't be handled and it has no fallback, let |
| 145 // it be handled as a plugin to show the broken plugin icon. |
| 146 bool use_fallback = |
| 147 object_type == ObjectContentType::kNone && HasFallbackContent(); |
| 148 return LoadPlugin(completed_url, service_type_, param_names, param_values, |
| 146 use_fallback, true); | 149 use_fallback, true); |
| 147 } | 150 } |
| 148 | 151 |
| 149 bool HTMLPlugInElement::CanProcessDrag() const { | 152 bool HTMLPlugInElement::CanProcessDrag() const { |
| 150 return PluginEmbeddedContentView() && | 153 return PluginEmbeddedContentView() && |
| 151 PluginEmbeddedContentView()->CanProcessDrag(); | 154 PluginEmbeddedContentView()->CanProcessDrag(); |
| 152 } | 155 } |
| 153 | 156 |
| 154 bool HTMLPlugInElement::CanStartSelection() const { | 157 bool HTMLPlugInElement::CanStartSelection() const { |
| 155 return UseFallbackContent() && Node::CanStartSelection(); | 158 return UseFallbackContent() && Node::CanStartSelection(); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 } | 190 } |
| 188 return; | 191 return; |
| 189 } | 192 } |
| 190 | 193 |
| 191 if (IsImageType()) { | 194 if (IsImageType()) { |
| 192 if (!image_loader_) | 195 if (!image_loader_) |
| 193 image_loader_ = HTMLImageLoader::Create(this); | 196 image_loader_ = HTMLImageLoader::Create(this); |
| 194 image_loader_->UpdateFromElement(); | 197 image_loader_->UpdateFromElement(); |
| 195 } else if (NeedsPluginUpdate() && !GetLayoutEmbeddedItem().IsNull() && | 198 } else if (NeedsPluginUpdate() && !GetLayoutEmbeddedItem().IsNull() && |
| 196 !GetLayoutEmbeddedItem().ShowsUnavailablePluginIndicator() && | 199 !GetLayoutEmbeddedItem().ShowsUnavailablePluginIndicator() && |
| 197 !WouldLoadAsNetscapePlugin(url_, service_type_) && | 200 GetObjectContentType() != ObjectContentType::kPlugin && |
| 198 !is_delaying_load_event_) { | 201 !is_delaying_load_event_) { |
| 199 is_delaying_load_event_ = true; | 202 is_delaying_load_event_ = true; |
| 200 GetDocument().IncrementLoadEventDelayCount(); | 203 GetDocument().IncrementLoadEventDelayCount(); |
| 201 GetDocument().LoadPluginsSoon(); | 204 GetDocument().LoadPluginsSoon(); |
| 202 } | 205 } |
| 203 } | 206 } |
| 204 | 207 |
| 205 void HTMLPlugInElement::UpdatePlugin() { | 208 void HTMLPlugInElement::UpdatePlugin() { |
| 206 UpdatePluginInternal(); | 209 UpdatePluginInternal(); |
| 207 if (is_delaying_load_event_) { | 210 if (is_delaying_load_event_) { |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 478 bool HTMLPlugInElement::LayoutObjectIsFocusable() const { | 481 bool HTMLPlugInElement::LayoutObjectIsFocusable() const { |
| 479 if (HTMLFrameOwnerElement::SupportsFocus() && | 482 if (HTMLFrameOwnerElement::SupportsFocus() && |
| 480 HTMLFrameOwnerElement::LayoutObjectIsFocusable()) | 483 HTMLFrameOwnerElement::LayoutObjectIsFocusable()) |
| 481 return true; | 484 return true; |
| 482 | 485 |
| 483 if (UseFallbackContent() || !HTMLFrameOwnerElement::LayoutObjectIsFocusable()) | 486 if (UseFallbackContent() || !HTMLFrameOwnerElement::LayoutObjectIsFocusable()) |
| 484 return false; | 487 return false; |
| 485 return plugin_is_available_; | 488 return plugin_is_available_; |
| 486 } | 489 } |
| 487 | 490 |
| 491 HTMLPlugInElement::ObjectContentType HTMLPlugInElement::GetObjectContentType() { |
| 492 String mime_type = service_type_; |
| 493 KURL url = GetDocument().CompleteURL(url_); |
| 494 if (mime_type.IsEmpty()) { |
| 495 // Try to guess the MIME type based off the extension. |
| 496 String filename = url.LastPathComponent(); |
| 497 int extension_pos = filename.ReverseFind('.'); |
| 498 if (extension_pos >= 0) { |
| 499 String extension = filename.Substring(extension_pos + 1); |
| 500 mime_type = MIMETypeRegistry::GetWellKnownMIMETypeForExtension(extension); |
| 501 } |
| 502 |
| 503 if (mime_type.IsEmpty()) |
| 504 return ObjectContentType::kFrame; |
| 505 } |
| 506 |
| 507 // If Chrome is started with the --disable-plugins switch, pluginData is 0. |
| 508 PluginData* plugin_data = GetDocument().GetFrame()->GetPluginData(); |
| 509 bool plugin_supports_mime_type = |
| 510 plugin_data && plugin_data->SupportsMimeType(mime_type); |
| 511 |
| 512 if (MIMETypeRegistry::IsSupportedImageMIMEType(mime_type)) { |
| 513 return should_prefer_plug_ins_for_images_ && plugin_supports_mime_type |
| 514 ? ObjectContentType::kPlugin |
| 515 : ObjectContentType::kImage; |
| 516 } |
| 517 |
| 518 if (plugin_supports_mime_type) |
| 519 return ObjectContentType::kPlugin; |
| 520 if (MIMETypeRegistry::IsSupportedNonImageMIMEType(mime_type)) |
| 521 return ObjectContentType::kFrame; |
| 522 return ObjectContentType::kNone; |
| 523 } |
| 524 |
| 488 bool HTMLPlugInElement::IsImageType() { | 525 bool HTMLPlugInElement::IsImageType() { |
| 489 if (service_type_.IsEmpty() && ProtocolIs(url_, "data")) | 526 if (service_type_.IsEmpty() && ProtocolIs(url_, "data")) |
| 490 service_type_ = MimeTypeFromDataURL(url_); | 527 service_type_ = MimeTypeFromDataURL(url_); |
| 491 | 528 |
| 492 if (LocalFrame* frame = GetDocument().GetFrame()) { | 529 if (GetDocument().GetFrame()) |
| 493 KURL completed_url = GetDocument().CompleteURL(url_); | 530 return GetObjectContentType() == ObjectContentType::kImage; |
| 494 return frame->Loader().Client()->GetObjectContentType( | |
| 495 completed_url, service_type_, ShouldPreferPlugInsForImages()) == | |
| 496 kObjectContentImage; | |
| 497 } | |
| 498 | |
| 499 return Image::SupportsType(service_type_); | 531 return Image::SupportsType(service_type_); |
| 500 } | 532 } |
| 501 | 533 |
| 502 LayoutEmbeddedItem HTMLPlugInElement::GetLayoutEmbeddedItem() const { | 534 LayoutEmbeddedItem HTMLPlugInElement::GetLayoutEmbeddedItem() const { |
| 503 // HTMLObjectElement and HTMLEmbedElement may return arbitrary layoutObjects | 535 // HTMLObjectElement and HTMLEmbedElement may return arbitrary layoutObjects |
| 504 // when using fallback content. | 536 // when using fallback content. |
| 505 if (!GetLayoutObject() || !GetLayoutObject()->IsEmbeddedObject()) | 537 if (!GetLayoutObject() || !GetLayoutObject()->IsEmbeddedObject()) |
| 506 return LayoutEmbeddedItem(nullptr); | 538 return LayoutEmbeddedItem(nullptr); |
| 507 return LayoutEmbeddedItem(ToLayoutEmbeddedObject(GetLayoutObject())); | 539 return LayoutEmbeddedItem(ToLayoutEmbeddedObject(GetLayoutObject())); |
| 508 } | 540 } |
| 509 | 541 |
| 510 // We don't use m_url, as it may not be the final URL that the object loads, | 542 // We don't use m_url, as it may not be the final URL that the object loads, |
| 511 // depending on <param> values. | 543 // depending on <param> values. |
| 512 bool HTMLPlugInElement::AllowedToLoadFrameURL(const String& url) { | 544 bool HTMLPlugInElement::AllowedToLoadFrameURL(const String& url) { |
| 513 KURL complete_url = GetDocument().CompleteURL(url); | 545 KURL complete_url = GetDocument().CompleteURL(url); |
| 514 return !(ContentFrame() && complete_url.ProtocolIsJavaScript() && | 546 return !(ContentFrame() && complete_url.ProtocolIsJavaScript() && |
| 515 !GetDocument().GetSecurityOrigin()->CanAccess( | 547 !GetDocument().GetSecurityOrigin()->CanAccess( |
| 516 ContentFrame()->GetSecurityContext()->GetSecurityOrigin())); | 548 ContentFrame()->GetSecurityContext()->GetSecurityOrigin())); |
| 517 } | 549 } |
| 518 | 550 |
| 519 // We don't use m_url, or m_serviceType as they may not be the final values | 551 bool HTMLPlugInElement::RequestObject(const Vector<String>& param_names, |
| 520 // that <object> uses depending on <param> values. | |
| 521 bool HTMLPlugInElement::WouldLoadAsNetscapePlugin(const String& url, | |
| 522 const String& service_type) { | |
| 523 DCHECK(GetDocument().GetFrame()); | |
| 524 KURL completed_url; | |
| 525 if (!url.IsEmpty()) | |
| 526 completed_url = GetDocument().CompleteURL(url); | |
| 527 return GetDocument().GetFrame()->Loader().Client()->GetObjectContentType( | |
| 528 completed_url, service_type, ShouldPreferPlugInsForImages()) == | |
| 529 kObjectContentNetscapePlugin; | |
| 530 } | |
| 531 | |
| 532 bool HTMLPlugInElement::RequestObject(const String& url, | |
| 533 const String& mime_type, | |
| 534 const Vector<String>& param_names, | |
| 535 const Vector<String>& param_values) { | 552 const Vector<String>& param_values) { |
| 536 bool result = | 553 bool result = RequestObjectInternal(param_names, param_values); |
| 537 RequestObjectInternal(url, mime_type, param_names, param_values); | |
| 538 | 554 |
| 539 DEFINE_STATIC_LOCAL( | 555 DEFINE_STATIC_LOCAL( |
| 540 EnumerationHistogram, result_histogram, | 556 EnumerationHistogram, result_histogram, |
| 541 ("Plugin.RequestObjectResult", kPluginRequestObjectResultMax)); | 557 ("Plugin.RequestObjectResult", kPluginRequestObjectResultMax)); |
| 542 result_histogram.Count(result ? kPluginRequestObjectResultSuccess | 558 result_histogram.Count(result ? kPluginRequestObjectResultSuccess |
| 543 : kPluginRequestObjectResultFailure); | 559 : kPluginRequestObjectResultFailure); |
| 544 | 560 |
| 545 return result; | 561 return result; |
| 546 } | 562 } |
| 547 | 563 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 602 // Make sure any input event handlers introduced by the plugin are taken into | 618 // Make sure any input event handlers introduced by the plugin are taken into |
| 603 // account. | 619 // account. |
| 604 if (Page* page = GetDocument().GetFrame()->GetPage()) { | 620 if (Page* page = GetDocument().GetFrame()->GetPage()) { |
| 605 if (ScrollingCoordinator* scrolling_coordinator = | 621 if (ScrollingCoordinator* scrolling_coordinator = |
| 606 page->GetScrollingCoordinator()) | 622 page->GetScrollingCoordinator()) |
| 607 scrolling_coordinator->NotifyGeometryChanged(); | 623 scrolling_coordinator->NotifyGeometryChanged(); |
| 608 } | 624 } |
| 609 return true; | 625 return true; |
| 610 } | 626 } |
| 611 | 627 |
| 612 bool HTMLPlugInElement::ShouldUsePlugin(const KURL& url, | |
| 613 const String& mime_type, | |
| 614 bool has_fallback, | |
| 615 bool& use_fallback) { | |
| 616 ObjectContentType object_type = | |
| 617 GetDocument().GetFrame()->Loader().Client()->GetObjectContentType( | |
| 618 url, mime_type, ShouldPreferPlugInsForImages()); | |
| 619 // If an object's content can't be handled and it has no fallback, let | |
| 620 // it be handled as a plugin to show the broken plugin icon. | |
| 621 use_fallback = object_type == kObjectContentNone && has_fallback; | |
| 622 return object_type == kObjectContentNone || | |
| 623 object_type == kObjectContentNetscapePlugin; | |
| 624 } | |
| 625 | |
| 626 void HTMLPlugInElement::DispatchErrorEvent() { | 628 void HTMLPlugInElement::DispatchErrorEvent() { |
| 627 if (GetDocument().IsPluginDocument() && GetDocument().LocalOwner()) | 629 if (GetDocument().IsPluginDocument() && GetDocument().LocalOwner()) |
| 628 GetDocument().LocalOwner()->DispatchEvent( | 630 GetDocument().LocalOwner()->DispatchEvent( |
| 629 Event::Create(EventTypeNames::error)); | 631 Event::Create(EventTypeNames::error)); |
| 630 else | 632 else |
| 631 DispatchEvent(Event::Create(EventTypeNames::error)); | 633 DispatchEvent(Event::Create(EventTypeNames::error)); |
| 632 } | 634 } |
| 633 | 635 |
| 634 bool HTMLPlugInElement::AllowedToLoadObject(const KURL& url, | 636 bool HTMLPlugInElement::AllowedToLoadObject(const KURL& url, |
| 635 const String& mime_type) { | 637 const String& mime_type) { |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 692 | 694 |
| 693 void HTMLPlugInElement::LazyReattachIfNeeded() { | 695 void HTMLPlugInElement::LazyReattachIfNeeded() { |
| 694 if (!UseFallbackContent() && NeedsPluginUpdate() && GetLayoutObject() && | 696 if (!UseFallbackContent() && NeedsPluginUpdate() && GetLayoutObject() && |
| 695 !IsImageType()) { | 697 !IsImageType()) { |
| 696 LazyReattachIfAttached(); | 698 LazyReattachIfAttached(); |
| 697 SetPersistedPlugin(nullptr); | 699 SetPersistedPlugin(nullptr); |
| 698 } | 700 } |
| 699 } | 701 } |
| 700 | 702 |
| 701 } // namespace blink | 703 } // namespace blink |
| OLD | NEW |