• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2006, 2007, 2008 Apple Inc. All Rights Reserved.
3  * Copyright (C) 2008 Collabora, Ltd. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
15  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
18  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  */
26 
27 #include "config.h"
28 #include "PluginMessageThrottlerWin.h"
29 
30 #include "PluginView.h"
31 #include <wtf/ASCIICType.h>
32 
33 using namespace WTF;
34 
35 namespace WebCore {
36 
37 static const double MessageThrottleTimeInterval = 0.001;
38 
PluginMessageThrottlerWin(PluginView * pluginView)39 PluginMessageThrottlerWin::PluginMessageThrottlerWin(PluginView* pluginView)
40     : m_back(0), m_front(0)
41     , m_pluginView(pluginView)
42     , m_messageThrottleTimer(this, &PluginMessageThrottlerWin::messageThrottleTimerFired)
43 {
44     // Initialize the free list with our inline messages
45     for (unsigned i = 0; i < NumInlineMessages - 1; i++)
46         m_inlineMessages[i].next = &m_inlineMessages[i + 1];
47     m_inlineMessages[NumInlineMessages - 1].next = 0;
48     m_freeInlineMessages = &m_inlineMessages[0];
49 }
50 
~PluginMessageThrottlerWin()51 PluginMessageThrottlerWin::~PluginMessageThrottlerWin()
52 {
53     PluginMessage* next;
54 
55     for (PluginMessage* message = m_front; message; message = next) {
56         next = message->next;
57         freeMessage(message);
58     }
59 }
60 
appendMessage(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam)61 void PluginMessageThrottlerWin::appendMessage(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
62 {
63     PluginMessage* message = allocateMessage();
64 
65     message->hWnd = hWnd;
66     message->msg = msg;
67     message->wParam = wParam;
68     message->lParam = lParam;
69     message->next = 0;
70 
71     if (m_back)
72         m_back->next = message;
73     m_back = message;
74     if (!m_front)
75         m_front = message;
76 
77     if (!m_messageThrottleTimer.isActive())
78         m_messageThrottleTimer.startOneShot(MessageThrottleTimeInterval);
79 }
80 
messageThrottleTimerFired(Timer<PluginMessageThrottlerWin> *)81 void PluginMessageThrottlerWin::messageThrottleTimerFired(Timer<PluginMessageThrottlerWin>*)
82 {
83     PluginMessage* message = m_front;
84     m_front = m_front->next;
85     if (message == m_back)
86         m_back = 0;
87 
88     ::CallWindowProc(m_pluginView->pluginWndProc(), message->hWnd, message->msg, message->wParam, message->lParam);
89 
90     freeMessage(message);
91 
92     if (m_front)
93         m_messageThrottleTimer.startOneShot(MessageThrottleTimeInterval);
94 }
95 
allocateMessage()96 PluginMessage* PluginMessageThrottlerWin::allocateMessage()
97 {
98     PluginMessage *message;
99 
100     if (m_freeInlineMessages) {
101         message = m_freeInlineMessages;
102         m_freeInlineMessages = message->next;
103     } else
104         message = new PluginMessage;
105 
106     return message;
107 }
108 
isInlineMessage(PluginMessage * message)109 bool PluginMessageThrottlerWin::isInlineMessage(PluginMessage* message)
110 {
111     return message >= &m_inlineMessages[0] && message <= &m_inlineMessages[NumInlineMessages - 1];
112 }
113 
freeMessage(PluginMessage * message)114 void PluginMessageThrottlerWin::freeMessage(PluginMessage* message)
115 {
116     if (isInlineMessage(message)) {
117         message->next = m_freeInlineMessages;
118         m_freeInlineMessages = message;
119     } else
120         delete message;
121 }
122 
123 } // namespace WebCore
124