tizen beta release
[framework/web/webkit-efl.git] / Source / WebKit / chromium / src / WebPluginContainerImpl.cpp
1 /*
2  * Copyright (C) 2009 Google Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
8  *     * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *     * Redistributions in binary form must reproduce the above
11  * copyright notice, this list of conditions and the following disclaimer
12  * in the documentation and/or other materials provided with the
13  * distribution.
14  *     * Neither the name of Google Inc. nor the names of its
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30
31 #include "config.h"
32 #include "WebPluginContainerImpl.h"
33
34 #include "Chrome.h"
35 #include "ChromeClientImpl.h"
36 #include "PluginLayerChromium.h"
37 #include "ScrollbarGroup.h"
38 #include "WebClipboard.h"
39 #include "WebCursorInfo.h"
40 #include "WebDataSourceImpl.h"
41 #include "WebElement.h"
42 #include "WebInputEvent.h"
43 #include "WebInputEventConversion.h"
44 #include "WebKit.h"
45 #include "WebKitPlatformSupport.h"
46 #include "WebPlugin.h"
47 #include "WebRect.h"
48 #include "WebString.h"
49 #include "WebURL.h"
50 #include "WebURLError.h"
51 #include "WebURLRequest.h"
52 #include "WebVector.h"
53 #include "WebViewImpl.h"
54 #include "WrappedResourceResponse.h"
55
56 #include "EventNames.h"
57 #include "FocusController.h"
58 #include "FormState.h"
59 #include "Frame.h"
60 #include "FrameLoadRequest.h"
61 #include "FrameView.h"
62 #include "GraphicsContext.h"
63 #include "HostWindow.h"
64 #include "HTMLFormElement.h"
65 #include "HTMLNames.h"
66 #include "HTMLPlugInElement.h"
67 #include "IFrameShimSupport.h"
68 #include "KeyboardCodes.h"
69 #include "KeyboardEvent.h"
70 #include "MouseEvent.h"
71 #include "Page.h"
72 #include "RenderBox.h"
73 #include "ScrollAnimator.h"
74 #include "ScrollView.h"
75 #include "ScrollbarTheme.h"
76 #include "UserGestureIndicator.h"
77 #include "WheelEvent.h"
78
79 #if ENABLE(GESTURE_EVENTS)
80 #include "PlatformGestureEvent.h"
81 #endif
82
83 #if WEBKIT_USING_SKIA
84 #include "PlatformContextSkia.h"
85 #endif
86
87 using namespace WebCore;
88
89 namespace WebKit {
90
91 // Public methods --------------------------------------------------------------
92
93 void WebPluginContainerImpl::setFrameRect(const IntRect& frameRect)
94 {
95     Widget::setFrameRect(frameRect);
96     reportGeometry();
97 }
98
99 void WebPluginContainerImpl::paint(GraphicsContext* gc, const IntRect& damageRect)
100 {
101     if (gc->updatingControlTints() && m_scrollbarGroup) {
102         // See comment in FrameView::updateControlTints().
103         if (m_scrollbarGroup->horizontalScrollbar())
104             m_scrollbarGroup->horizontalScrollbar()->invalidate();
105         if (m_scrollbarGroup->verticalScrollbar())
106             m_scrollbarGroup->verticalScrollbar()->invalidate();
107     }
108
109     if (gc->paintingDisabled())
110         return;
111
112     if (!parent())
113         return;
114
115     // Don't paint anything if the plugin doesn't intersect the damage rect.
116     if (!frameRect().intersects(damageRect))
117         return;
118
119     gc->save();
120
121     ASSERT(parent()->isFrameView());
122     ScrollView* view = parent();
123
124     // The plugin is positioned in window coordinates, so it needs to be painted
125     // in window coordinates.
126     IntPoint origin = view->windowToContents(IntPoint(0, 0));
127     gc->translate(static_cast<float>(origin.x()), static_cast<float>(origin.y()));
128
129 #if WEBKIT_USING_SKIA
130     WebCanvas* canvas = gc->platformContext()->canvas();
131 #elif WEBKIT_USING_CG
132     WebCanvas* canvas = gc->platformContext();
133 #endif
134
135     IntRect windowRect =
136         IntRect(view->contentsToWindow(damageRect.location()), damageRect.size());
137     m_webPlugin->paint(canvas, windowRect);
138
139     gc->restore();
140 }
141
142 void WebPluginContainerImpl::invalidateRect(const IntRect& rect)
143 {
144     if (!parent())
145         return;
146
147     RenderBox* renderer = toRenderBox(m_element->renderer());
148
149     IntRect dirtyRect = rect;
150     dirtyRect.move(renderer->borderLeft() + renderer->paddingLeft(),
151                    renderer->borderTop() + renderer->paddingTop());
152     renderer->repaintRectangle(dirtyRect);
153 }
154
155 void WebPluginContainerImpl::setFocus(bool focused)
156 {
157     Widget::setFocus(focused);
158     m_webPlugin->updateFocus(focused);
159 }
160
161 void WebPluginContainerImpl::show()
162 {
163     setSelfVisible(true);
164     m_webPlugin->updateVisibility(true);
165
166     Widget::show();
167 }
168
169 void WebPluginContainerImpl::hide()
170 {
171     setSelfVisible(false);
172     m_webPlugin->updateVisibility(false);
173
174     Widget::hide();
175 }
176
177 void WebPluginContainerImpl::handleEvent(Event* event)
178 {
179     if (!m_webPlugin->acceptsInputEvents())
180         return;
181
182     RefPtr<WebPluginContainerImpl> protector(this);
183     // The events we pass are defined at:
184     //    http://devedge-temp.mozilla.org/library/manuals/2002/plugin/1.0/structures5.html#1000000
185     // Don't take the documentation as truth, however.  There are many cases
186     // where mozilla behaves differently than the spec.
187     if (event->isMouseEvent())
188         handleMouseEvent(static_cast<MouseEvent*>(event));
189     else if (event->hasInterface(eventNames().interfaceForWheelEvent))
190         handleWheelEvent(static_cast<WheelEvent*>(event));
191     else if (event->isKeyboardEvent())
192         handleKeyboardEvent(static_cast<KeyboardEvent*>(event));
193
194     // FIXME: it would be cleaner if Widget::handleEvent returned true/false and
195     // HTMLPluginElement called setDefaultHandled or defaultEventHandler.
196     if (!event->defaultHandled())
197         m_element->Node::defaultEventHandler(event);
198 }
199
200 void WebPluginContainerImpl::frameRectsChanged()
201 {
202     Widget::frameRectsChanged();
203     reportGeometry();
204 }
205
206 void WebPluginContainerImpl::widgetPositionsUpdated()
207 {
208     Widget::widgetPositionsUpdated();
209     reportGeometry();
210 }
211
212 void WebPluginContainerImpl::setParentVisible(bool parentVisible)
213 {
214     // We override this function to make sure that geometry updates are sent
215     // over to the plugin. For e.g. when a plugin is instantiated it does not
216     // have a valid parent. As a result the first geometry update from webkit
217     // is ignored. This function is called when the plugin eventually gets a
218     // parent.
219
220     if (isParentVisible() == parentVisible)
221         return;  // No change.
222
223     Widget::setParentVisible(parentVisible);
224     if (!isSelfVisible())
225         return;  // This widget has explicitely been marked as not visible.
226
227     m_webPlugin->updateVisibility(isVisible());
228 }
229
230 void WebPluginContainerImpl::setParent(ScrollView* view)
231 {
232     // We override this function so that if the plugin is windowed, we can call
233     // NPP_SetWindow at the first possible moment.  This ensures that
234     // NPP_SetWindow is called before the manual load data is sent to a plugin.
235     // If this order is reversed, Flash won't load videos.
236
237     Widget::setParent(view);
238     if (view)
239         reportGeometry();
240 }
241
242 bool WebPluginContainerImpl::supportsPaginatedPrint() const
243 {
244     return m_webPlugin->supportsPaginatedPrint();
245 }
246
247 bool WebPluginContainerImpl::isPrintScalingDisabled() const
248 {
249     return m_webPlugin->isPrintScalingDisabled();
250 }
251
252 int WebPluginContainerImpl::printBegin(const IntRect& printableArea,
253                                        int printerDPI) const
254 {
255     return m_webPlugin->printBegin(printableArea, printerDPI);
256 }
257
258 bool WebPluginContainerImpl::printPage(int pageNumber,
259                                        WebCore::GraphicsContext* gc)
260 {
261     gc->save();
262 #if WEBKIT_USING_SKIA
263     WebCanvas* canvas = gc->platformContext()->canvas();
264 #elif WEBKIT_USING_CG
265     WebCanvas* canvas = gc->platformContext();
266 #endif
267     bool ret = m_webPlugin->printPage(pageNumber, canvas);
268     gc->restore();
269     return ret;
270 }
271
272 void WebPluginContainerImpl::printEnd()
273 {
274     m_webPlugin->printEnd();
275 }
276
277 void WebPluginContainerImpl::copy()
278 {
279     if (!m_webPlugin->hasSelection())
280         return;
281
282     webKitPlatformSupport()->clipboard()->writeHTML(m_webPlugin->selectionAsMarkup(), WebURL(), m_webPlugin->selectionAsText(), false);
283 }
284
285 WebElement WebPluginContainerImpl::element()
286 {
287     return WebElement(m_element);
288 }
289
290 void WebPluginContainerImpl::invalidate()
291 {
292     Widget::invalidate();
293 }
294
295 void WebPluginContainerImpl::invalidateRect(const WebRect& rect)
296 {
297     invalidateRect(static_cast<IntRect>(rect));
298 }
299
300 void WebPluginContainerImpl::scrollRect(int dx, int dy, const WebRect& rect)
301 {
302     Widget* parentWidget = parent();
303     if (parentWidget->isFrameView()) {
304         FrameView* parentFrameView = static_cast<FrameView*>(parentWidget);
305         if (!parentFrameView->isOverlapped()) {
306             IntRect damageRect = convertToContainingWindow(static_cast<IntRect>(rect));
307             IntSize scrollDelta(dx, dy);
308             // scroll() only uses the second rectangle, clipRect, and ignores the first
309             // rectangle.
310             parent()->hostWindow()->scroll(scrollDelta, damageRect, damageRect);
311             return;
312         }
313     }
314
315     // Use slow scrolling instead.
316     invalidateRect(rect);
317 }
318
319 void WebPluginContainerImpl::reportGeometry()
320 {
321     if (!parent())
322         return;
323
324     IntRect windowRect, clipRect;
325     Vector<IntRect> cutOutRects;
326     calculateGeometry(frameRect(), windowRect, clipRect, cutOutRects);
327
328     m_webPlugin->updateGeometry(windowRect, clipRect, cutOutRects, isVisible());
329
330     if (m_scrollbarGroup)
331         m_scrollbarGroup->scrollAnimator()->contentsResized();
332 }
333
334 void WebPluginContainerImpl::setBackingTextureId(unsigned id)
335 {
336 #if USE(ACCELERATED_COMPOSITING)
337     unsigned currId = m_platformLayer->textureId();
338     if (currId == id)
339         return;
340
341     m_platformLayer->setTextureId(id);
342     // If anyone of the IDs is zero we need to switch between hardware
343     // and software compositing. This is done by triggering a style recalc
344     // on the container element.
345     if (!(currId * id))
346         m_element->setNeedsStyleRecalc(WebCore::SyntheticStyleChange);
347 #endif
348 }
349
350 void WebPluginContainerImpl::setBackingIOSurfaceId(int width,
351                                                    int height,
352                                                    uint32_t ioSurfaceId)
353 {
354 #if OS(DARWIN) && USE(ACCELERATED_COMPOSITING)
355     uint32_t currentId = m_platformLayer->getIOSurfaceId();
356     if (ioSurfaceId == currentId)
357         return;
358
359     m_platformLayer->setIOSurfaceProperties(width, height, ioSurfaceId);
360
361     // If anyone of the IDs is zero we need to switch between hardware
362     // and software compositing. This is done by triggering a style recalc
363     // on the container element.
364     if (!(ioSurfaceId * currentId))
365         m_element->setNeedsStyleRecalc(WebCore::SyntheticStyleChange);
366 #endif
367 }
368
369 void WebPluginContainerImpl::commitBackingTexture()
370 {
371 #if USE(ACCELERATED_COMPOSITING)
372     if (platformLayer())
373         platformLayer()->setNeedsDisplay();
374 #endif
375 }
376
377 void WebPluginContainerImpl::clearScriptObjects()
378 {
379     Frame* frame = m_element->document()->frame();
380     if (!frame)
381         return;
382     frame->script()->cleanupScriptObjectsForPlugin(this);
383 }
384
385 NPObject* WebPluginContainerImpl::scriptableObjectForElement()
386 {
387     return m_element->getNPObject();
388 }
389
390 WebString WebPluginContainerImpl::executeScriptURL(const WebURL& url, bool popupsAllowed)
391 {
392     Frame* frame = m_element->document()->frame();
393     if (!frame)
394         return WebString();
395
396     const KURL& kurl = url;
397     ASSERT(kurl.protocolIs("javascript"));
398
399     String script = decodeURLEscapeSequences(
400         kurl.string().substring(strlen("javascript:")));
401
402     ScriptValue result = frame->script()->executeScript(script, popupsAllowed);
403
404     // Failure is reported as a null string.
405     String resultStr;
406     result.getString(resultStr);
407     return resultStr;
408 }
409
410 void WebPluginContainerImpl::loadFrameRequest(const WebURLRequest& request, const WebString& target, bool notifyNeeded, void* notifyData)
411 {
412     Frame* frame = m_element->document()->frame();
413     if (!frame || !frame->loader()->documentLoader())
414         return;  // FIXME: send a notification in this case?
415
416     if (notifyNeeded) {
417         // FIXME: This is a bit of hack to allow us to observe completion of
418         // our frame request.  It would be better to evolve FrameLoader to
419         // support a completion callback instead.
420         OwnPtr<WebPluginLoadObserver> observer = adoptPtr(new WebPluginLoadObserver(this, request.url(), notifyData));
421         // FIXME: Calling get here is dangerous! What if observer is freed?
422         m_pluginLoadObservers.append(observer.get());
423         WebDataSourceImpl::setNextPluginLoadObserver(observer.release());
424     }
425
426     FrameLoadRequest frameRequest(frame->document()->securityOrigin(), request.toResourceRequest(), target);
427     UserGestureIndicator gestureIndicator(request.hasUserGesture() ? DefinitelyProcessingUserGesture : PossiblyProcessingUserGesture);
428     frame->loader()->loadFrameRequest(frameRequest, false, false, 0, 0, MaybeSendReferrer);
429 }
430
431 void WebPluginContainerImpl::zoomLevelChanged(double zoomLevel)
432 {
433     WebViewImpl* view = WebViewImpl::fromPage(m_element->document()->frame()->page());
434     view->fullFramePluginZoomLevelChanged(zoomLevel);
435 }
436
437 void WebPluginContainerImpl::didReceiveResponse(const ResourceResponse& response)
438 {
439     // Make sure that the plugin receives window geometry before data, or else
440     // plugins misbehave.
441     frameRectsChanged();
442
443     WrappedResourceResponse urlResponse(response);
444     m_webPlugin->didReceiveResponse(urlResponse);
445 }
446
447 void WebPluginContainerImpl::didReceiveData(const char *data, int dataLength)
448 {
449     m_webPlugin->didReceiveData(data, dataLength);
450 }
451
452 void WebPluginContainerImpl::didFinishLoading()
453 {
454     m_webPlugin->didFinishLoading();
455 }
456
457 void WebPluginContainerImpl::didFailLoading(const ResourceError& error)
458 {
459     m_webPlugin->didFailLoading(error);
460 }
461
462 NPObject* WebPluginContainerImpl::scriptableObject()
463 {
464     return m_webPlugin->scriptableObject();
465 }
466
467 void WebPluginContainerImpl::willDestroyPluginLoadObserver(WebPluginLoadObserver* observer)
468 {
469     size_t pos = m_pluginLoadObservers.find(observer);
470     if (pos == notFound)
471         return;
472     m_pluginLoadObservers.remove(pos);
473 }
474
475 #if USE(ACCELERATED_COMPOSITING)
476 WebCore::LayerChromium* WebPluginContainerImpl::platformLayer() const
477 {
478     return (m_platformLayer->textureId() || m_platformLayer->getIOSurfaceId()) ? m_platformLayer.get() : 0;
479 }
480 #endif
481
482
483 ScrollbarGroup* WebPluginContainerImpl::scrollbarGroup()
484 {
485     if (!m_scrollbarGroup)
486         m_scrollbarGroup = adoptPtr(new ScrollbarGroup(m_element->document()->frame()->page()));
487     return m_scrollbarGroup.get();
488 }
489
490 void WebPluginContainerImpl::willStartLiveResize()
491 {
492     if (m_scrollbarGroup)
493         m_scrollbarGroup->willStartLiveResize();
494 }
495
496 void WebPluginContainerImpl::willEndLiveResize()
497 {
498     if (m_scrollbarGroup)
499         m_scrollbarGroup->willEndLiveResize();
500 }
501
502 bool WebPluginContainerImpl::paintCustomOverhangArea(GraphicsContext* context, const IntRect& horizontalOverhangArea, const IntRect& verticalOverhangArea, const IntRect& dirtyRect)
503 {
504     context->save();
505     context->setFillColor(Color(0xCC, 0xCC, 0xCC), ColorSpaceDeviceRGB);
506     context->fillRect(intersection(horizontalOverhangArea, dirtyRect));
507     context->fillRect(intersection(verticalOverhangArea, dirtyRect));
508     context->restore();
509     return true;
510 }
511
512 #if ENABLE(GESTURE_EVENTS)
513 bool WebPluginContainerImpl::handleGestureEvent(const WebCore::PlatformGestureEvent& gestureEvent)
514 {
515     if (m_scrollbarGroup) {
516         m_scrollbarGroup->handleGestureEvent(gestureEvent);
517         return true;
518     }
519     return false;
520 }
521 #endif
522
523 // Private methods -------------------------------------------------------------
524
525 WebPluginContainerImpl::WebPluginContainerImpl(WebCore::HTMLPlugInElement* element, WebPlugin* webPlugin)
526     : WebCore::PluginViewBase(0)
527     , m_element(element)
528     , m_webPlugin(webPlugin)
529 #if USE(ACCELERATED_COMPOSITING)
530     , m_platformLayer(PluginLayerChromium::create(0))
531 #endif
532 {
533 }
534
535 WebPluginContainerImpl::~WebPluginContainerImpl()
536 {
537     for (size_t i = 0; i < m_pluginLoadObservers.size(); ++i)
538         m_pluginLoadObservers[i]->clearPluginContainer();
539     m_webPlugin->destroy();
540 }
541
542 void WebPluginContainerImpl::handleMouseEvent(MouseEvent* event)
543 {
544     ASSERT(parent()->isFrameView());
545
546     // We cache the parent FrameView here as the plugin widget could be deleted
547     // in the call to HandleEvent. See http://b/issue?id=1362948
548     FrameView* parentView = static_cast<FrameView*>(parent());
549
550     WebMouseEventBuilder webEvent(this, *event);
551     if (webEvent.type == WebInputEvent::Undefined)
552         return;
553
554     if (event->type() == eventNames().mousedownEvent) {
555         Frame* containingFrame = parentView->frame();
556         if (Page* currentPage = containingFrame->page())
557             currentPage->focusController()->setFocusedNode(m_element, containingFrame);
558         else
559             containingFrame->document()->setFocusedNode(m_element);
560     }
561
562     if (m_scrollbarGroup) {
563         // This needs to be set before the other callbacks in this scope, since
564         // the scroll animator class might query the position in response.
565         m_scrollbarGroup->setLastMousePosition(IntPoint(event->x(), event->y()));
566         if (event->type() == eventNames().mousemoveEvent)
567             m_scrollbarGroup->scrollAnimator()->mouseMovedInContentArea();
568         else if (event->type() == eventNames().mouseoverEvent)
569             m_scrollbarGroup->scrollAnimator()->mouseEnteredContentArea();
570         else if (event->type() == eventNames().mouseoutEvent)
571             m_scrollbarGroup->scrollAnimator()->mouseExitedContentArea();
572     }
573
574     WebCursorInfo cursorInfo;
575     if (m_webPlugin->handleInputEvent(webEvent, cursorInfo))
576         event->setDefaultHandled();
577
578     // A windowless plugin can change the cursor in response to a mouse move
579     // event.  We need to reflect the changed cursor in the frame view as the
580     // mouse is moved in the boundaries of the windowless plugin.
581     Page* page = parentView->frame()->page();
582     if (!page)
583         return;
584     ChromeClientImpl* chromeClient =
585         static_cast<ChromeClientImpl*>(page->chrome()->client());
586     chromeClient->setCursorForPlugin(cursorInfo);
587 }
588
589 void WebPluginContainerImpl::handleWheelEvent(WheelEvent* event)
590 {
591     WebMouseWheelEventBuilder webEvent(this, *event);
592     if (webEvent.type == WebInputEvent::Undefined)
593         return;
594
595     WebCursorInfo cursorInfo;
596     if (m_webPlugin->handleInputEvent(webEvent, cursorInfo))
597         event->setDefaultHandled();
598 }
599
600 void WebPluginContainerImpl::handleKeyboardEvent(KeyboardEvent* event)
601 {
602     WebKeyboardEventBuilder webEvent(*event);
603     if (webEvent.type == WebInputEvent::Undefined)
604         return;
605
606     if (webEvent.type == WebInputEvent::KeyDown) {
607 #if OS(DARWIN)
608         if (webEvent.modifiers == WebInputEvent::MetaKey
609 #else
610         if (webEvent.modifiers == WebInputEvent::ControlKey
611 #endif
612             && webEvent.windowsKeyCode == VKEY_C
613             // Only copy if there's a selection, so that we only ever do this
614             // for Pepper plugins that support copying.  Windowless NPAPI
615             // plugins will get the event as before.
616             && m_webPlugin->hasSelection()) {
617             copy();
618             event->setDefaultHandled();
619             return;
620         }
621     }
622
623     const WebInputEvent* currentInputEvent = WebViewImpl::currentInputEvent();
624
625     // Copy stashed info over, and only copy here in order not to interfere
626     // the ctrl-c logic above.
627     if (currentInputEvent
628         && WebInputEvent::isKeyboardEventType(currentInputEvent->type)) {
629         webEvent.modifiers |= currentInputEvent->modifiers &
630             (WebInputEvent::CapsLockOn | WebInputEvent::NumLockOn);
631     }
632
633     WebCursorInfo cursorInfo;
634     if (m_webPlugin->handleInputEvent(webEvent, cursorInfo))
635         event->setDefaultHandled();
636 }
637
638 void WebPluginContainerImpl::calculateGeometry(const IntRect& frameRect,
639                                                IntRect& windowRect,
640                                                IntRect& clipRect,
641                                                Vector<IntRect>& cutOutRects)
642 {
643     windowRect = IntRect(
644         parent()->contentsToWindow(frameRect.location()), frameRect.size());
645
646     // Calculate a clip-rect so that we don't overlap the scrollbars, etc.
647     clipRect = windowClipRect();
648     clipRect.move(-windowRect.x(), -windowRect.y());
649
650     getPluginOcclusions(m_element, this->parent(), frameRect, cutOutRects);
651     // Convert to the plugin position.
652     for (size_t i = 0; i < cutOutRects.size(); i++)
653         cutOutRects[i].move(-frameRect.x(), -frameRect.y());
654 }
655
656 WebCore::IntRect WebPluginContainerImpl::windowClipRect() const
657 {
658     // Start by clipping to our bounds.
659     IntRect clipRect =
660         convertToContainingWindow(IntRect(0, 0, width(), height()));
661
662     // document()->renderer() can be 0 when we receive messages from the
663     // plugins while we are destroying a frame.
664     if (m_element->renderer()->document()->renderer()) {
665         // Take our element and get the clip rect from the enclosing layer and
666         // frame view.
667         RenderLayer* layer = m_element->renderer()->enclosingLayer();
668         clipRect.intersect(
669             m_element->document()->view()->windowClipRectForLayer(layer, true));
670     }
671
672     return clipRect;
673 }
674
675 } // namespace WebKit