Diff
Modified: trunk/Source/WebKit2/ChangeLog (93911 => 93912)
--- trunk/Source/WebKit2/ChangeLog 2011-08-26 21:36:12 UTC (rev 93911)
+++ trunk/Source/WebKit2/ChangeLog 2011-08-26 21:36:42 UTC (rev 93912)
@@ -1,3 +1,42 @@
+2011-08-26 Anders Carlsson <[email protected]>
+
+ Implement NPN_ScheduleTimer/NPN_UnscheduleTimer
+ https://bugs.webkit.org/show_bug.cgi?id=67062
+
+ Reviewed by Sam Weinig.
+
+ * WebProcess/Plugins/Netscape/NetscapeBrowserFuncs.cpp:
+ (WebKit::NPN_ScheduleTimer):
+ Call NetscapePlugin::scheduleTimer.
+
+ (WebKit::NPN_UnscheduleTimer):
+ Call NetscapePlugin::unscheduleTimer.
+
+ * WebProcess/Plugins/Netscape/NetscapePlugin.cpp:
+ (WebKit::NetscapePlugin::NetscapePlugin):
+ Initialize m_nextTimerID.
+
+ (WebKit::NetscapePlugin::Timer::start):
+ Start the timer.
+
+ (WebKit::NetscapePlugin::Timer::stop):
+ Stop the timer.
+
+ (WebKit::NetscapePlugin::Timer::timerFired):
+ Call the right callback and unschedule the timer object if it's not a repeating timer.
+
+ (WebKit::NetscapePlugin::scheduleTimer):
+ Create a new timer and start it.
+
+ (WebKit::NetscapePlugin::unscheduleTimer):
+ Get the timer from the map and destroy it.
+
+ (WebKit::NetscapePlugin::destroy):
+ Destroy all timers.
+
+ * WebProcess/Plugins/Netscape/NetscapePlugin.h:
+ Add Timer class.
+
2011-08-26 Sam Weinig <[email protected]>
Fix typo in Connection.cpp
Modified: trunk/Source/WebKit2/WebProcess/Plugins/Netscape/NetscapeBrowserFuncs.cpp (93911 => 93912)
--- trunk/Source/WebKit2/WebProcess/Plugins/Netscape/NetscapeBrowserFuncs.cpp 2011-08-26 21:36:12 UTC (rev 93911)
+++ trunk/Source/WebKit2/WebProcess/Plugins/Netscape/NetscapeBrowserFuncs.cpp 2011-08-26 21:36:42 UTC (rev 93912)
@@ -950,15 +950,18 @@
return NPERR_NO_ERROR;
}
-static uint32_t NPN_ScheduleTimer(NPP instance, uint32_t interval, NPBool repeat, void (*timerFunc)(NPP npp, uint32_t timerID))
+static uint32_t NPN_ScheduleTimer(NPP npp, uint32_t interval, NPBool repeat, void (*timerFunc)(NPP npp, uint32_t timerID))
{
- notImplemented();
- return NPERR_GENERIC_ERROR;
+ RefPtr<NetscapePlugin> plugin = NetscapePlugin::fromNPP(npp);
+
+ return plugin->scheduleTimer(interval, repeat, timerFunc);
}
-static void NPN_UnscheduleTimer(NPP instance, uint32_t timerID)
+static void NPN_UnscheduleTimer(NPP npp, uint32_t timerID)
{
- notImplemented();
+ RefPtr<NetscapePlugin> plugin = NetscapePlugin::fromNPP(npp);
+
+ plugin->unscheduleTimer(timerID);
}
#if PLATFORM(MAC)
Modified: trunk/Source/WebKit2/WebProcess/Plugins/Netscape/NetscapePlugin.cpp (93911 => 93912)
--- trunk/Source/WebKit2/WebProcess/Plugins/Netscape/NetscapePlugin.cpp 2011-08-26 21:36:12 UTC (rev 93911)
+++ trunk/Source/WebKit2/WebProcess/Plugins/Netscape/NetscapePlugin.cpp 2011-08-26 21:36:42 UTC (rev 93912)
@@ -68,6 +68,7 @@
, m_isTransparent(false)
, m_inNPPNew(false)
, m_loadManually(false)
+ , m_nextTimerID(0)
#if PLATFORM(MAC)
, m_drawingModel(static_cast<NPDrawingModel>(-1))
, m_eventModel(static_cast<NPEventModel>(-1))
@@ -97,6 +98,7 @@
NetscapePlugin::~NetscapePlugin()
{
ASSERT(!m_isStarted);
+ ASSERT(m_timers.isEmpty());
m_pluginModule->decrementLoadCount();
}
@@ -314,6 +316,77 @@
function(userData);
}
+PassOwnPtr<NetscapePlugin::Timer> NetscapePlugin::Timer::create(NetscapePlugin* netscapePlugin, unsigned timerID, unsigned interval, bool repeat, TimerFunc timerFunc)
+{
+ return adoptPtr(new Timer(netscapePlugin, timerID, interval, repeat, timerFunc));
+}
+
+NetscapePlugin::Timer::Timer(NetscapePlugin* netscapePlugin, unsigned timerID, unsigned interval, bool repeat, TimerFunc timerFunc)
+ : m_netscapePlugin(netscapePlugin)
+ , m_timerID(timerID)
+ , m_interval(interval)
+ , m_repeat(repeat)
+ , m_timerFunc(timerFunc)
+ , m_timer(RunLoop::main(), this, &Timer::timerFired)
+{
+}
+
+NetscapePlugin::Timer::~Timer()
+{
+}
+
+void NetscapePlugin::Timer::start()
+{
+ double timeInterval = m_interval / 1000.0;
+
+ if (m_repeat)
+ m_timer.startRepeating(timeInterval);
+ else
+ m_timer.startOneShot(timeInterval);
+}
+
+void NetscapePlugin::Timer::stop()
+{
+ m_timer.stop();
+}
+
+void NetscapePlugin::Timer::timerFired()
+{
+ m_timerFunc(&m_netscapePlugin->m_npp, m_timerID);
+
+ if (!m_repeat)
+ m_netscapePlugin->unscheduleTimer(m_timerID);
+}
+
+uint32_t NetscapePlugin::scheduleTimer(unsigned interval, bool repeat, void (*timerFunc)(NPP, unsigned timerID))
+{
+ if (!timerFunc)
+ return 0;
+
+ // FIXME: Handle wrapping around.
+ unsigned timerID = ++m_nextTimerID;
+
+ OwnPtr<Timer> timer = Timer::create(this, timerID, interval, repeat, timerFunc);
+
+ // FIXME: Based on the plug-in visibility, figure out if we should throttle the timer, or if we should start it at all.
+ timer->start();
+ m_timers.set(timerID, timer.leakPtr());
+
+ return timerID;
+}
+
+void NetscapePlugin::unscheduleTimer(unsigned timerID)
+{
+ TimerMap::iterator it = m_timers.find(timerID);
+ if (it == m_timers.end())
+ return;
+
+ OwnPtr<Timer> timer = adoptPtr(it->second);
+ m_timers.remove(it);
+
+ timer->stop();
+}
+
String NetscapePlugin::proxiesForURL(const String& urlString)
{
return controller()->proxiesForURL(urlString);
@@ -549,6 +622,9 @@
m_isStarted = false;
platformDestroy();
+
+ deleteAllValues(m_timers);
+ m_timers.clear();
}
void NetscapePlugin::paint(GraphicsContext* context, const IntRect& dirtyRect)
Modified: trunk/Source/WebKit2/WebProcess/Plugins/Netscape/NetscapePlugin.h (93911 => 93912)
--- trunk/Source/WebKit2/WebProcess/Plugins/Netscape/NetscapePlugin.h 2011-08-26 21:36:12 UTC (rev 93911)
+++ trunk/Source/WebKit2/WebProcess/Plugins/Netscape/NetscapePlugin.h 2011-08-26 21:36:42 UTC (rev 93912)
@@ -109,6 +109,9 @@
// Called on the plug-in run loop (which is currently the main thread run loop).
void handlePluginThreadAsyncCall(void (*function)(void*), void* userData);
+ unsigned scheduleTimer(unsigned interval, bool repeat, void (*timerFunc)(NPP, unsigned timerID));
+ void unscheduleTimer(unsigned timerID);
+
String proxiesForURL(const String& urlString);
String cookiesForURL(const String& urlString);
void setCookiesForURL(const String& urlString, const String& cookieString);
@@ -233,6 +236,37 @@
RefPtr<NetscapePluginStream> m_manualStream;
Vector<bool, 8> m_popupEnabledStates;
+ class Timer {
+ WTF_MAKE_NONCOPYABLE(Timer);
+
+ public:
+ typedef void (*TimerFunc)(NPP, uint32 timerID);
+
+ static PassOwnPtr<Timer> create(NetscapePlugin*, unsigned timerID, unsigned interval, bool repeat, TimerFunc);
+ ~Timer();
+
+ void start();
+ void stop();
+
+ private:
+ Timer(NetscapePlugin*, unsigned timerID, unsigned interval, bool repeat, TimerFunc);
+
+ void timerFired();
+
+ // This is a weak pointer since Timer objects are destroyed before the NetscapePlugin object itself is destroyed.
+ NetscapePlugin* m_netscapePlugin;
+
+ unsigned m_timerID;
+ unsigned m_interval;
+ bool m_repeat;
+ TimerFunc m_timerFunc;
+
+ RunLoop::Timer<Timer> m_timer;
+ };
+ typedef HashMap<unsigned, Timer*> TimerMap;
+ TimerMap m_timers;
+ unsigned m_nextTimerID;
+
#if PLUGIN_ARCHITECTURE(MAC)
NPDrawingModel m_drawingModel;
NPEventModel m_eventModel;