| 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 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 462 bool HTMLPlugInElement::LayoutObjectIsFocusable() const { | 465 bool HTMLPlugInElement::LayoutObjectIsFocusable() const { |
| 463 if (HTMLFrameOwnerElement::SupportsFocus() && | 466 if (HTMLFrameOwnerElement::SupportsFocus() && |
| 464 HTMLFrameOwnerElement::LayoutObjectIsFocusable()) | 467 HTMLFrameOwnerElement::LayoutObjectIsFocusable()) |
| 465 return true; | 468 return true; |
| 466 | 469 |
| 467 if (UseFallbackContent() || !HTMLFrameOwnerElement::LayoutObjectIsFocusable()) | 470 if (UseFallbackContent() || !HTMLFrameOwnerElement::LayoutObjectIsFocusable()) |
| 468 return false; | 471 return false; |
| 469 return plugin_is_available_; | 472 return plugin_is_available_; |
| 470 } | 473 } |
| 471 | 474 |
| 475 HTMLPlugInElement::ObjectContentType HTMLPlugInElement::GetObjectContentType() { |
| 476 String mime_type = service_type_; |
| 477 KURL url = GetDocument().CompleteURL(url_); |
| 478 if (mime_type.IsEmpty()) { |
| 479 // Try to guess the MIME type based off the extension. |
| 480 String filename = url.LastPathComponent(); |
| 481 int extension_pos = filename.ReverseFind('.'); |
| 482 if (extension_pos >= 0) { |
| 483 String extension = filename.Substring(extension_pos + 1); |
| 484 mime_type = MIMETypeRegistry::GetWellKnownMIMETypeForExtension(extension); |
| 485 } |
| 486 |
| 487 if (mime_type.IsEmpty()) |
| 488 return ObjectContentType::kFrame; |
| 489 } |
| 490 |
| 491 // If Chrome is started with the --disable-plugins switch, pluginData is 0. |
| 492 PluginData* plugin_data = GetDocument().GetFrame()->GetPluginData(); |
| 493 bool plugin_supports_mime_type = |
| 494 plugin_data && plugin_data->SupportsMimeType(mime_type); |
| 495 |
| 496 if (MIMETypeRegistry::IsSupportedImageMIMEType(mime_type)) { |
| 497 return should_prefer_plug_ins_for_images_ && plugin_supports_mime_type |
| 498 ? ObjectContentType::kPlugin |
| 499 : ObjectContentType::kImage; |
| 500 } |
| 501 |
| 502 if (plugin_supports_mime_type) |
| 503 return ObjectContentType::kPlugin; |
| 504 if (MIMETypeRegistry::IsSupportedNonImageMIMEType(mime_type)) |
| 505 return ObjectContentType::kFrame; |
| 506 return ObjectContentType::kNone; |
| 507 } |
| 508 |
| 472 bool HTMLPlugInElement::IsImageType() { | 509 bool HTMLPlugInElement::IsImageType() { |
| 473 if (service_type_.IsEmpty() && ProtocolIs(url_, "data")) | 510 if (service_type_.IsEmpty() && ProtocolIs(url_, "data")) |
| 474 service_type_ = MimeTypeFromDataURL(url_); | 511 service_type_ = MimeTypeFromDataURL(url_); |
| 475 | 512 |
| 476 if (LocalFrame* frame = GetDocument().GetFrame()) { | 513 if (GetDocument().GetFrame()) |
| 477 KURL completed_url = GetDocument().CompleteURL(url_); | 514 return GetObjectContentType() == ObjectContentType::kImage; |
| 478 return frame->Loader().Client()->GetObjectContentType( | |
| 479 completed_url, service_type_, ShouldPreferPlugInsForImages()) == | |
| 480 kObjectContentImage; | |
| 481 } | |
| 482 | |
| 483 return Image::SupportsType(service_type_); | 515 return Image::SupportsType(service_type_); |
| 484 } | 516 } |
| 485 | 517 |
| 486 LayoutEmbeddedItem HTMLPlugInElement::GetLayoutEmbeddedItem() const { | 518 LayoutEmbeddedItem HTMLPlugInElement::GetLayoutEmbeddedItem() const { |
| 487 // HTMLObjectElement and HTMLEmbedElement may return arbitrary layoutObjects | 519 // HTMLObjectElement and HTMLEmbedElement may return arbitrary layoutObjects |
| 488 // when using fallback content. | 520 // when using fallback content. |
| 489 if (!GetLayoutObject() || !GetLayoutObject()->IsEmbeddedObject()) | 521 if (!GetLayoutObject() || !GetLayoutObject()->IsEmbeddedObject()) |
| 490 return LayoutEmbeddedItem(nullptr); | 522 return LayoutEmbeddedItem(nullptr); |
| 491 return LayoutEmbeddedItem(ToLayoutEmbeddedObject(GetLayoutObject())); | 523 return LayoutEmbeddedItem(ToLayoutEmbeddedObject(GetLayoutObject())); |
| 492 } | 524 } |
| 493 | 525 |
| 494 // We don't use m_url, as it may not be the final URL that the object loads, | 526 // We don't use m_url, as it may not be the final URL that the object loads, |
| 495 // depending on <param> values. | 527 // depending on <param> values. |
| 496 bool HTMLPlugInElement::AllowedToLoadFrameURL(const String& url) { | 528 bool HTMLPlugInElement::AllowedToLoadFrameURL(const String& url) { |
| 497 KURL complete_url = GetDocument().CompleteURL(url); | 529 KURL complete_url = GetDocument().CompleteURL(url); |
| 498 return !(ContentFrame() && complete_url.ProtocolIsJavaScript() && | 530 return !(ContentFrame() && complete_url.ProtocolIsJavaScript() && |
| 499 !GetDocument().GetSecurityOrigin()->CanAccess( | 531 !GetDocument().GetSecurityOrigin()->CanAccess( |
| 500 ContentFrame()->GetSecurityContext()->GetSecurityOrigin())); | 532 ContentFrame()->GetSecurityContext()->GetSecurityOrigin())); |
| 501 } | 533 } |
| 502 | 534 |
| 503 // We don't use m_url, or m_serviceType as they may not be the final values | 535 bool HTMLPlugInElement::RequestObject(const Vector<String>& param_names, |
| 504 // that <object> uses depending on <param> values. | |
| 505 bool HTMLPlugInElement::WouldLoadAsNetscapePlugin(const String& url, | |
| 506 const String& service_type) { | |
| 507 DCHECK(GetDocument().GetFrame()); | |
| 508 KURL completed_url; | |
| 509 if (!url.IsEmpty()) | |
| 510 completed_url = GetDocument().CompleteURL(url); | |
| 511 return GetDocument().GetFrame()->Loader().Client()->GetObjectContentType( | |
| 512 completed_url, service_type, ShouldPreferPlugInsForImages()) == | |
| 513 kObjectContentNetscapePlugin; | |
| 514 } | |
| 515 | |
| 516 bool HTMLPlugInElement::RequestObject(const String& url, | |
| 517 const String& mime_type, | |
| 518 const Vector<String>& param_names, | |
| 519 const Vector<String>& param_values) { | 536 const Vector<String>& param_values) { |
| 520 bool result = | 537 bool result = RequestObjectInternal(param_names, param_values); |
| 521 RequestObjectInternal(url, mime_type, param_names, param_values); | |
| 522 | 538 |
| 523 DEFINE_STATIC_LOCAL( | 539 DEFINE_STATIC_LOCAL( |
| 524 EnumerationHistogram, result_histogram, | 540 EnumerationHistogram, result_histogram, |
| 525 ("Plugin.RequestObjectResult", kPluginRequestObjectResultMax)); | 541 ("Plugin.RequestObjectResult", kPluginRequestObjectResultMax)); |
| 526 result_histogram.Count(result ? kPluginRequestObjectResultSuccess | 542 result_histogram.Count(result ? kPluginRequestObjectResultSuccess |
| 527 : kPluginRequestObjectResultFailure); | 543 : kPluginRequestObjectResultFailure); |
| 528 | 544 |
| 529 return result; | 545 return result; |
| 530 } | 546 } |
| 531 | 547 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 586 // Make sure any input event handlers introduced by the plugin are taken into | 602 // Make sure any input event handlers introduced by the plugin are taken into |
| 587 // account. | 603 // account. |
| 588 if (Page* page = GetDocument().GetFrame()->GetPage()) { | 604 if (Page* page = GetDocument().GetFrame()->GetPage()) { |
| 589 if (ScrollingCoordinator* scrolling_coordinator = | 605 if (ScrollingCoordinator* scrolling_coordinator = |
| 590 page->GetScrollingCoordinator()) | 606 page->GetScrollingCoordinator()) |
| 591 scrolling_coordinator->NotifyGeometryChanged(); | 607 scrolling_coordinator->NotifyGeometryChanged(); |
| 592 } | 608 } |
| 593 return true; | 609 return true; |
| 594 } | 610 } |
| 595 | 611 |
| 596 bool HTMLPlugInElement::ShouldUsePlugin(const KURL& url, | |
| 597 const String& mime_type, | |
| 598 bool has_fallback, | |
| 599 bool& use_fallback) { | |
| 600 ObjectContentType object_type = | |
| 601 GetDocument().GetFrame()->Loader().Client()->GetObjectContentType( | |
| 602 url, mime_type, ShouldPreferPlugInsForImages()); | |
| 603 // If an object's content can't be handled and it has no fallback, let | |
| 604 // it be handled as a plugin to show the broken plugin icon. | |
| 605 use_fallback = object_type == kObjectContentNone && has_fallback; | |
| 606 return object_type == kObjectContentNone || | |
| 607 object_type == kObjectContentNetscapePlugin; | |
| 608 } | |
| 609 | |
| 610 void HTMLPlugInElement::DispatchErrorEvent() { | 612 void HTMLPlugInElement::DispatchErrorEvent() { |
| 611 if (GetDocument().IsPluginDocument() && GetDocument().LocalOwner()) | 613 if (GetDocument().IsPluginDocument() && GetDocument().LocalOwner()) |
| 612 GetDocument().LocalOwner()->DispatchEvent( | 614 GetDocument().LocalOwner()->DispatchEvent( |
| 613 Event::Create(EventTypeNames::error)); | 615 Event::Create(EventTypeNames::error)); |
| 614 else | 616 else |
| 615 DispatchEvent(Event::Create(EventTypeNames::error)); | 617 DispatchEvent(Event::Create(EventTypeNames::error)); |
| 616 } | 618 } |
| 617 | 619 |
| 618 bool HTMLPlugInElement::AllowedToLoadObject(const KURL& url, | 620 bool HTMLPlugInElement::AllowedToLoadObject(const KURL& url, |
| 619 const String& mime_type) { | 621 const String& mime_type) { |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 676 | 678 |
| 677 void HTMLPlugInElement::LazyReattachIfNeeded() { | 679 void HTMLPlugInElement::LazyReattachIfNeeded() { |
| 678 if (!UseFallbackContent() && NeedsPluginUpdate() && GetLayoutObject() && | 680 if (!UseFallbackContent() && NeedsPluginUpdate() && GetLayoutObject() && |
| 679 !IsImageType()) { | 681 !IsImageType()) { |
| 680 LazyReattachIfAttached(); | 682 LazyReattachIfAttached(); |
| 681 SetPersistedPlugin(nullptr); | 683 SetPersistedPlugin(nullptr); |
| 682 } | 684 } |
| 683 } | 685 } |
| 684 | 686 |
| 685 } // namespace blink | 687 } // namespace blink |
| OLD | NEW |