Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(415)

Side by Side Diff: Source/core/html/HTMLPlugInImageElement.cpp

Issue 23819007: Have Node::document() return a reference instead of a pointer (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase on master Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/html/HTMLPlugInElement.cpp ('k') | Source/core/html/HTMLProgressElement.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2008, 2011, 2012 Apple Inc. All rights reserved. 2 * Copyright (C) 2008, 2011, 2012 Apple Inc. All rights reserved.
3 * 3 *
4 * This library is free software; you can redistribute it and/or 4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public 5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either 6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version. 7 * version 2 of the License, or (at your option) any later version.
8 * 8 *
9 * This library is distributed in the hope that it will be useful, 9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 if (!renderer() || !renderer()->isEmbeddedObject()) 81 if (!renderer() || !renderer()->isEmbeddedObject())
82 return 0; 82 return 0;
83 return toRenderEmbeddedObject(renderer()); 83 return toRenderEmbeddedObject(renderer());
84 } 84 }
85 85
86 bool HTMLPlugInImageElement::isImageType() 86 bool HTMLPlugInImageElement::isImageType()
87 { 87 {
88 if (m_serviceType.isEmpty() && protocolIs(m_url, "data")) 88 if (m_serviceType.isEmpty() && protocolIs(m_url, "data"))
89 m_serviceType = mimeTypeFromDataURL(m_url); 89 m_serviceType = mimeTypeFromDataURL(m_url);
90 90
91 if (Frame* frame = document()->frame()) { 91 if (Frame* frame = document().frame()) {
92 KURL completedURL = document()->completeURL(m_url); 92 KURL completedURL = document().completeURL(m_url);
93 return frame->loader()->client()->objectContentType(completedURL, m_serv iceType, shouldPreferPlugInsForImages()) == ObjectContentImage; 93 return frame->loader()->client()->objectContentType(completedURL, m_serv iceType, shouldPreferPlugInsForImages()) == ObjectContentImage;
94 } 94 }
95 95
96 return Image::supportsType(m_serviceType); 96 return Image::supportsType(m_serviceType);
97 } 97 }
98 98
99 // We don't use m_url, as it may not be the final URL that the object loads, 99 // We don't use m_url, as it may not be the final URL that the object loads,
100 // depending on <param> values. 100 // depending on <param> values.
101 bool HTMLPlugInImageElement::allowedToLoadFrameURL(const String& url) 101 bool HTMLPlugInImageElement::allowedToLoadFrameURL(const String& url)
102 { 102 {
103 KURL completeURL = document()->completeURL(url); 103 KURL completeURL = document().completeURL(url);
104 104
105 if (contentFrame() && protocolIsJavaScript(completeURL) 105 if (contentFrame() && protocolIsJavaScript(completeURL)
106 && !document()->securityOrigin()->canAccess(contentDocument()->securityO rigin())) 106 && !document().securityOrigin()->canAccess(contentDocument()->securityOr igin()))
107 return false; 107 return false;
108 108
109 return document()->frame()->isURLAllowed(completeURL); 109 return document().frame()->isURLAllowed(completeURL);
110 } 110 }
111 111
112 // We don't use m_url, or m_serviceType as they may not be the final values 112 // We don't use m_url, or m_serviceType as they may not be the final values
113 // that <object> uses depending on <param> values. 113 // that <object> uses depending on <param> values.
114 bool HTMLPlugInImageElement::wouldLoadAsNetscapePlugin(const String& url, const String& serviceType) 114 bool HTMLPlugInImageElement::wouldLoadAsNetscapePlugin(const String& url, const String& serviceType)
115 { 115 {
116 ASSERT(document()); 116 ASSERT(document().frame());
117 ASSERT(document()->frame());
118 KURL completedURL; 117 KURL completedURL;
119 if (!url.isEmpty()) 118 if (!url.isEmpty())
120 completedURL = document()->completeURL(url); 119 completedURL = document().completeURL(url);
121 120
122 FrameLoader* frameLoader = document()->frame()->loader(); 121 FrameLoader* frameLoader = document().frame()->loader();
123 ASSERT(frameLoader); 122 ASSERT(frameLoader);
124 if (frameLoader->client()->objectContentType(completedURL, serviceType, shou ldPreferPlugInsForImages()) == ObjectContentNetscapePlugin) 123 if (frameLoader->client()->objectContentType(completedURL, serviceType, shou ldPreferPlugInsForImages()) == ObjectContentNetscapePlugin)
125 return true; 124 return true;
126 return false; 125 return false;
127 } 126 }
128 127
129 RenderObject* HTMLPlugInImageElement::createRenderer(RenderStyle* style) 128 RenderObject* HTMLPlugInImageElement::createRenderer(RenderStyle* style)
130 { 129 {
131 // Fallback content breaks the DOM->Renderer class relationship of this 130 // Fallback content breaks the DOM->Renderer class relationship of this
132 // class and all superclasses because createObject won't necessarily 131 // class and all superclasses because createObject won't necessarily
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 // we can end up detaching during an attach() call, before we even have a 173 // we can end up detaching during an attach() call, before we even have a
175 // renderer. In that case, don't mark the widget for update. 174 // renderer. In that case, don't mark the widget for update.
176 if (attached() && renderer() && !useFallbackContent()) 175 if (attached() && renderer() && !useFallbackContent())
177 // Update the widget the next time we attach (detaching destroys the plu gin). 176 // Update the widget the next time we attach (detaching destroys the plu gin).
178 setNeedsWidgetUpdate(true); 177 setNeedsWidgetUpdate(true);
179 HTMLPlugInElement::detach(context); 178 HTMLPlugInElement::detach(context);
180 } 179 }
181 180
182 void HTMLPlugInImageElement::updateWidgetIfNecessary() 181 void HTMLPlugInImageElement::updateWidgetIfNecessary()
183 { 182 {
184 document()->updateStyleIfNeeded(); 183 document().updateStyleIfNeeded();
185 184
186 if (!needsWidgetUpdate() || useFallbackContent() || isImageType()) 185 if (!needsWidgetUpdate() || useFallbackContent() || isImageType())
187 return; 186 return;
188 187
189 if (!renderEmbeddedObject() || renderEmbeddedObject()->showsUnavailablePlugi nIndicator()) 188 if (!renderEmbeddedObject() || renderEmbeddedObject()->showsUnavailablePlugi nIndicator())
190 return; 189 return;
191 190
192 updateWidget(CreateOnlyNonNetscapePlugins); 191 updateWidget(CreateOnlyNonNetscapePlugins);
193 } 192 }
194 193
(...skipping 24 matching lines...) Expand all
219 { 218 {
220 if (url.isEmpty() && mimeType.isEmpty()) 219 if (url.isEmpty() && mimeType.isEmpty())
221 return false; 220 return false;
222 221
223 // FIXME: None of this code should use renderers! 222 // FIXME: None of this code should use renderers!
224 RenderEmbeddedObject* renderer = renderEmbeddedObject(); 223 RenderEmbeddedObject* renderer = renderEmbeddedObject();
225 ASSERT(renderer); 224 ASSERT(renderer);
226 if (!renderer) 225 if (!renderer)
227 return false; 226 return false;
228 227
229 KURL completedURL = document()->completeURL(url); 228 KURL completedURL = document().completeURL(url);
230 229
231 bool useFallback; 230 bool useFallback;
232 if (shouldUsePlugin(completedURL, mimeType, renderer->hasFallbackContent(), useFallback)) { 231 if (shouldUsePlugin(completedURL, mimeType, renderer->hasFallbackContent(), useFallback)) {
233 bool success = loadPlugin(completedURL, mimeType, paramNames, paramValue s, useFallback); 232 bool success = loadPlugin(completedURL, mimeType, paramNames, paramValue s, useFallback);
234 return success; 233 return success;
235 } 234 }
236 235
237 // If the plug-in element already contains a subframe, loadOrRedirectSubfram e will re-use it. Otherwise, 236 // If the plug-in element already contains a subframe, loadOrRedirectSubfram e will re-use it. Otherwise,
238 // it will create a new frame and set it as the RenderPart's widget, causing what was previously 237 // it will create a new frame and set it as the RenderPart's widget, causing what was previously
239 // in the widget to be torn down. 238 // in the widget to be torn down.
240 return loadOrRedirectSubframe(completedURL, getNameAttribute(), true); 239 return loadOrRedirectSubframe(completedURL, getNameAttribute(), true);
241 } 240 }
242 241
243 bool HTMLPlugInImageElement::loadPlugin(const KURL& url, const String& mimeType, const Vector<String>& paramNames, const Vector<String>& paramValues, bool useFa llback) 242 bool HTMLPlugInImageElement::loadPlugin(const KURL& url, const String& mimeType, const Vector<String>& paramNames, const Vector<String>& paramValues, bool useFa llback)
244 { 243 {
245 Frame* frame = document()->frame(); 244 Frame* frame = document().frame();
246 245
247 if (!frame->loader()->allowPlugins(AboutToInstantiatePlugin)) 246 if (!frame->loader()->allowPlugins(AboutToInstantiatePlugin))
248 return false; 247 return false;
249 248
250 if (!pluginIsLoadable(url, mimeType)) 249 if (!pluginIsLoadable(url, mimeType))
251 return false; 250 return false;
252 251
253 RenderEmbeddedObject* renderer = renderEmbeddedObject(); 252 RenderEmbeddedObject* renderer = renderEmbeddedObject();
254 253
255 // FIXME: This code should not depend on renderer! 254 // FIXME: This code should not depend on renderer!
256 if (!renderer || useFallback) 255 if (!renderer || useFallback)
257 return false; 256 return false;
258 257
259 LOG(Plugins, "%p Plug-in URL: %s", this, m_url.utf8().data()); 258 LOG(Plugins, "%p Plug-in URL: %s", this, m_url.utf8().data());
260 LOG(Plugins, " Loaded URL: %s", url.string().utf8().data()); 259 LOG(Plugins, " Loaded URL: %s", url.string().utf8().data());
261 m_loadedUrl = url; 260 m_loadedUrl = url;
262 261
263 IntSize contentSize = roundedIntSize(LayoutSize(renderer->contentWidth(), re nderer->contentHeight())); 262 IntSize contentSize = roundedIntSize(LayoutSize(renderer->contentWidth(), re nderer->contentHeight()));
264 bool loadManually = document()->isPluginDocument() && !frame->loader()->cont ainsPlugins() && toPluginDocument(document())->shouldLoadPluginManually(); 263 bool loadManually = document().isPluginDocument() && !frame->loader()->conta insPlugins() && toPluginDocument(&document())->shouldLoadPluginManually();
265 RefPtr<Widget> widget = frame->loader()->client()->createPlugin(contentSize, this, url, paramNames, paramValues, mimeType, loadManually); 264 RefPtr<Widget> widget = frame->loader()->client()->createPlugin(contentSize, this, url, paramNames, paramValues, mimeType, loadManually);
266 265
267 if (!widget) { 266 if (!widget) {
268 if (!renderer->showsUnavailablePluginIndicator()) 267 if (!renderer->showsUnavailablePluginIndicator())
269 renderer->setPluginUnavailabilityReason(RenderEmbeddedObject::Plugin Missing); 268 renderer->setPluginUnavailabilityReason(RenderEmbeddedObject::Plugin Missing);
270 return false; 269 return false;
271 } 270 }
272 271
273 renderer->setWidget(widget); 272 renderer->setWidget(widget);
274 frame->loader()->setContainsPlugins(); 273 frame->loader()->setContainsPlugins();
275 setNeedsStyleRecalc(LocalStyleChange, StyleChangeFromRenderer); 274 setNeedsStyleRecalc(LocalStyleChange, StyleChangeFromRenderer);
276 return true; 275 return true;
277 } 276 }
278 277
279 bool HTMLPlugInImageElement::shouldUsePlugin(const KURL& url, const String& mime Type, bool hasFallback, bool& useFallback) 278 bool HTMLPlugInImageElement::shouldUsePlugin(const KURL& url, const String& mime Type, bool hasFallback, bool& useFallback)
280 { 279 {
281 // Allow other plug-ins to win over QuickTime because if the user has instal led a plug-in that 280 // Allow other plug-ins to win over QuickTime because if the user has instal led a plug-in that
282 // can handle TIFF (which QuickTime can also handle) they probably intended to override QT. 281 // can handle TIFF (which QuickTime can also handle) they probably intended to override QT.
283 if (document()->frame()->page() && (mimeType == "image/tiff" || mimeType == "image/tif" || mimeType == "image/x-tiff")) { 282 if (document().frame()->page() && (mimeType == "image/tiff" || mimeType == " image/tif" || mimeType == "image/x-tiff")) {
284 const PluginData* pluginData = document()->frame()->page()->pluginData() ; 283 const PluginData* pluginData = document().frame()->page()->pluginData();
285 String pluginName = pluginData ? pluginData->pluginNameForMimeType(mimeT ype) : String(); 284 String pluginName = pluginData ? pluginData->pluginNameForMimeType(mimeT ype) : String();
286 if (!pluginName.isEmpty() && !pluginName.contains("QuickTime", false)) 285 if (!pluginName.isEmpty() && !pluginName.contains("QuickTime", false))
287 return true; 286 return true;
288 } 287 }
289 288
290 ObjectContentType objectType = document()->frame()->loader()->client()->obje ctContentType(url, mimeType, shouldPreferPlugInsForImages()); 289 ObjectContentType objectType = document().frame()->loader()->client()->objec tContentType(url, mimeType, shouldPreferPlugInsForImages());
291 // If an object's content can't be handled and it has no fallback, let 290 // If an object's content can't be handled and it has no fallback, let
292 // it be handled as a plugin to show the broken plugin icon. 291 // it be handled as a plugin to show the broken plugin icon.
293 useFallback = objectType == ObjectContentNone && hasFallback; 292 useFallback = objectType == ObjectContentNone && hasFallback;
294 return objectType == ObjectContentNone || objectType == ObjectContentNetscap ePlugin || objectType == ObjectContentOtherPlugin; 293 return objectType == ObjectContentNone || objectType == ObjectContentNetscap ePlugin || objectType == ObjectContentOtherPlugin;
295 294
296 } 295 }
297 296
298 bool HTMLPlugInImageElement::pluginIsLoadable(const KURL& url, const String& mim eType) 297 bool HTMLPlugInImageElement::pluginIsLoadable(const KURL& url, const String& mim eType)
299 { 298 {
300 Frame* frame = document()->frame(); 299 Frame* frame = document().frame();
301 Settings* settings = frame->settings(); 300 Settings* settings = frame->settings();
302 if (!settings) 301 if (!settings)
303 return false; 302 return false;
304 303
305 if (MIMETypeRegistry::isJavaAppletMIMEType(mimeType)) { 304 if (MIMETypeRegistry::isJavaAppletMIMEType(mimeType)) {
306 if (!settings->isJavaEnabled()) 305 if (!settings->isJavaEnabled())
307 return false; 306 return false;
308 } 307 }
309 308
310 if (document()->isSandboxed(SandboxPlugins)) 309 if (document().isSandboxed(SandboxPlugins))
311 return false; 310 return false;
312 311
313 if (!document()->securityOrigin()->canDisplay(url)) { 312 if (!document().securityOrigin()->canDisplay(url)) {
314 FrameLoader::reportLocalLoadFailed(frame, url.string()); 313 FrameLoader::reportLocalLoadFailed(frame, url.string());
315 return false; 314 return false;
316 } 315 }
317 316
318 String declaredMimeType = document()->isPluginDocument() && document()->owne rElement() ? 317 String declaredMimeType = document().isPluginDocument() && document().ownerE lement() ?
319 document()->ownerElement()->fastGetAttribute(HTMLNames::typeAttr) : 318 document().ownerElement()->fastGetAttribute(HTMLNames::typeAttr) :
320 fastGetAttribute(HTMLNames::typeAttr); 319 fastGetAttribute(HTMLNames::typeAttr);
321 if (!document()->contentSecurityPolicy()->allowObjectFromSource(url) 320 if (!document().contentSecurityPolicy()->allowObjectFromSource(url)
322 || !document()->contentSecurityPolicy()->allowPluginType(mimeType, decla redMimeType, url)) { 321 || !document().contentSecurityPolicy()->allowPluginType(mimeType, declar edMimeType, url)) {
323 renderEmbeddedObject()->setPluginUnavailabilityReason(RenderEmbeddedObje ct::PluginBlockedByContentSecurityPolicy); 322 renderEmbeddedObject()->setPluginUnavailabilityReason(RenderEmbeddedObje ct::PluginBlockedByContentSecurityPolicy);
324 return false; 323 return false;
325 } 324 }
326 325
327 if (frame->loader() && !frame->loader()->mixedContentChecker()->canRunInsecu reContent(document()->securityOrigin(), url)) 326 if (frame->loader() && !frame->loader()->mixedContentChecker()->canRunInsecu reContent(document().securityOrigin(), url))
328 return false; 327 return false;
329 return true; 328 return true;
330 } 329 }
331 330
332 } // namespace WebCore 331 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/html/HTMLPlugInElement.cpp ('k') | Source/core/html/HTMLProgressElement.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698