diff options
author | raymes@chromium.org <raymes@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-12-17 23:51:21 +0000 |
---|---|---|
committer | raymes@chromium.org <raymes@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-12-17 23:51:21 +0000 |
commit | c9246538b8cde698bb7e31c851388521709f2a2a (patch) | |
tree | ccd484b141cc5bf0c1f12b6893326ab8934ad0e4 | |
parent | abeaebc46b5cdfa8a4fcea6a2e55b207dffd8e7e (diff) | |
download | chromium_src-c9246538b8cde698bb7e31c851388521709f2a2a.zip chromium_src-c9246538b8cde698bb7e31c851388521709f2a2a.tar.gz chromium_src-c9246538b8cde698bb7e31c851388521709f2a2a.tar.bz2 |
This refactors PPB_Flash GetLocalTimeZoneOffset to the new PPAPI resource model. The in process implementation is removed. Associated plugin delegate code is also removed.
BUG=
Review URL: https://chromiumcodereview.appspot.com/11516020
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@173578 0039d316-1c4b-4281-b951-d872f2087c98
22 files changed, 129 insertions, 156 deletions
diff --git a/chrome/test/ppapi/ppapi_browsertest.cc b/chrome/test/ppapi/ppapi_browsertest.cc index fb03318..0b6aaea 100644 --- a/chrome/test/ppapi/ppapi_browsertest.cc +++ b/chrome/test/ppapi/ppapi_browsertest.cc @@ -674,11 +674,9 @@ TEST_PPAPI_NACL_VIA_HTTP(NetworkMonitorPrivate_DeleteInCallback) TEST_PPAPI_NACL_VIA_HTTP(NetworkMonitorPrivate_ListObserver) TEST_PPAPI_IN_PROCESS(Flash_SetInstanceAlwaysOnTop) -TEST_PPAPI_IN_PROCESS(Flash_GetLocalTimeZoneOffset) TEST_PPAPI_IN_PROCESS(Flash_GetCommandLineArgs) TEST_PPAPI_IN_PROCESS(Flash_GetSetting) TEST_PPAPI_OUT_OF_PROCESS(Flash_SetInstanceAlwaysOnTop) -TEST_PPAPI_OUT_OF_PROCESS(Flash_GetLocalTimeZoneOffset) TEST_PPAPI_OUT_OF_PROCESS(Flash_GetCommandLineArgs) TEST_PPAPI_OUT_OF_PROCESS(Flash_GetSetting) @@ -905,6 +903,7 @@ TEST_PPAPI_OUT_OF_PROCESS(MessageLoop_Post) #endif // Going forward, Flash APIs will only work out-of-process. +TEST_PPAPI_OUT_OF_PROCESS(Flash_GetLocalTimeZoneOffset) TEST_PPAPI_OUT_OF_PROCESS(Flash_GetProxyForURL) TEST_PPAPI_OUT_OF_PROCESS(Flash_SetCrashData) TEST_PPAPI_OUT_OF_PROCESS(FlashClipboard) diff --git a/content/browser/renderer_host/pepper/pepper_flash_browser_host.cc b/content/browser/renderer_host/pepper/pepper_flash_browser_host.cc index ba4f75f..c27dfb0 100644 --- a/content/browser/renderer_host/pepper/pepper_flash_browser_host.cc +++ b/content/browser/renderer_host/pepper/pepper_flash_browser_host.cc @@ -4,12 +4,14 @@ #include "content/browser/renderer_host/pepper/pepper_flash_browser_host.h" +#include "base/time.h" #include "content/public/browser/browser_ppapi_host.h" #include "ipc/ipc_message_macros.h" #include "ppapi/c/pp_errors.h" #include "ppapi/host/dispatch_host_message.h" #include "ppapi/proxy/ppapi_messages.h" #include "ppapi/proxy/resource_message_params.h" +#include "ppapi/shared_impl/time_conversion.h" #ifdef OS_WIN #include <windows.h> @@ -35,6 +37,8 @@ int32_t PepperFlashBrowserHost::OnResourceMessageReceived( IPC_BEGIN_MESSAGE_MAP(PepperFlashBrowserHost, msg) PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_Flash_UpdateActivity, OnMsgUpdateActivity); + PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_Flash_GetLocalTimeZoneOffset, + OnMsgGetLocalTimeZoneOffset); IPC_END_MESSAGE_MAP() return PP_ERROR_FAILED; } @@ -57,4 +61,15 @@ int32_t PepperFlashBrowserHost::OnMsgUpdateActivity( return PP_OK; } +int32_t PepperFlashBrowserHost::OnMsgGetLocalTimeZoneOffset( + ppapi::host::HostMessageContext* host_context, + const base::Time& t) { + // The reason for this processing being in the browser process is that on + // Linux, the localtime calls require filesystem access prohibited by the + // sandbox. + host_context->reply_msg = PpapiPluginMsg_Flash_GetLocalTimeZoneOffsetReply( + ppapi::PPGetLocalTimeZoneOffset(t)); + return PP_OK; +} + } // namespace content diff --git a/content/browser/renderer_host/pepper/pepper_flash_browser_host.h b/content/browser/renderer_host/pepper/pepper_flash_browser_host.h index 307fe94..8306012 100644 --- a/content/browser/renderer_host/pepper/pepper_flash_browser_host.h +++ b/content/browser/renderer_host/pepper/pepper_flash_browser_host.h @@ -9,6 +9,10 @@ #include "ppapi/host/host_message_context.h" #include "ppapi/host/resource_host.h" +namespace base { +class Time; +} + namespace content { class BrowserPpapiHost; @@ -27,6 +31,9 @@ class PepperFlashBrowserHost : public ppapi::host::ResourceHost { private: int32_t OnMsgUpdateActivity(ppapi::host::HostMessageContext* host_context); + int32_t OnMsgGetLocalTimeZoneOffset( + ppapi::host::HostMessageContext* host_context, + const base::Time& t); DISALLOW_COPY_AND_ASSIGN(PepperFlashBrowserHost); }; diff --git a/content/browser/renderer_host/pepper/pepper_message_filter.cc b/content/browser/renderer_host/pepper/pepper_message_filter.cc index 3383bba..c9bda2d 100644 --- a/content/browser/renderer_host/pepper/pepper_message_filter.cc +++ b/content/browser/renderer_host/pepper/pepper_message_filter.cc @@ -138,8 +138,6 @@ bool PepperMessageFilter::OnMessageReceived(const IPC::Message& msg, bool* message_was_ok) { bool handled = true; IPC_BEGIN_MESSAGE_MAP_EX(PepperMessageFilter, msg, *message_was_ok) - IPC_MESSAGE_HANDLER(PepperMsg_GetLocalTimeZoneOffset, - OnGetLocalTimeZoneOffset) IPC_MESSAGE_HANDLER_DELAY_REPLY(PpapiHostMsg_PPBInstance_GetFontFamilies, OnGetFontFamilies) // TCP messages. @@ -245,28 +243,6 @@ PepperMessageFilter::~PepperMessageFilter() { net::NetworkChangeNotifier::RemoveIPAddressObserver(this); } -void PepperMessageFilter::OnGetLocalTimeZoneOffset(base::Time t, - double* result) { - // Explode it to local time and then unexplode it as if it were UTC. Also - // explode it to UTC and unexplode it (this avoids mismatching rounding or - // lack thereof). The time zone offset is their difference. - // - // The reason for this processing being in the browser process is that on - // Linux, the localtime calls require filesystem access prohibited by the - // sandbox. - base::Time::Exploded exploded = { 0 }; - base::Time::Exploded utc_exploded = { 0 }; - t.LocalExplode(&exploded); - t.UTCExplode(&utc_exploded); - if (exploded.HasValidValues() && utc_exploded.HasValidValues()) { - base::Time adj_time = base::Time::FromUTCExploded(exploded); - base::Time cur = base::Time::FromUTCExploded(utc_exploded); - *result = (adj_time - cur).InSecondsF(); - } else { - *result = 0.0; - } -} - void PepperMessageFilter::OnGetFontFamilies(IPC::Message* reply_msg) { GetFontListAsync( base::Bind(&PepperMessageFilter::GetFontFamiliesComplete, diff --git a/content/browser/renderer_host/pepper/pepper_message_filter.h b/content/browser/renderer_host/pepper/pepper_message_filter.h index 04f88ad..977ca3b 100644 --- a/content/browser/renderer_host/pepper/pepper_message_filter.h +++ b/content/browser/renderer_host/pepper/pepper_message_filter.h @@ -14,7 +14,6 @@ #include "base/memory/linked_ptr.h" #include "base/memory/scoped_ptr.h" #include "base/process.h" -#include "base/time.h" #include "content/public/browser/browser_message_filter.h" #include "content/public/browser/content_browser_client.h" #include "net/base/net_util.h" @@ -136,7 +135,6 @@ class PepperMessageFilter // notifications. typedef std::set<uint32> NetworkMonitorIdSet; - void OnGetLocalTimeZoneOffset(base::Time t, double* result); void OnGetFontFamilies(IPC::Message* reply); void OnTCPCreate(int32 routing_id, diff --git a/content/renderer/pepper/pepper_plugin_delegate_impl.cc b/content/renderer/pepper/pepper_plugin_delegate_impl.cc index 3f6249d..d16fbfb 100644 --- a/content/renderer/pepper/pepper_plugin_delegate_impl.cc +++ b/content/renderer/pepper/pepper_plugin_delegate_impl.cc @@ -1364,13 +1364,6 @@ void PepperPluginDelegateImpl::SaveURLAs(const GURL& url) { render_view_->routing_id(), url, referrer)); } -double PepperPluginDelegateImpl::GetLocalTimeZoneOffset(base::Time t) { - double result = 0.0; - render_view_->Send(new PepperMsg_GetLocalTimeZoneOffset( - t, &result)); - return result; -} - PP_FlashLSORestrictions PepperPluginDelegateImpl::GetLocalDataRestrictions( const GURL& document_url, const GURL& plugin_url) { diff --git a/content/renderer/pepper/pepper_plugin_delegate_impl.h b/content/renderer/pepper/pepper_plugin_delegate_impl.h index 700bbef..1b6bafd 100644 --- a/content/renderer/pepper/pepper_plugin_delegate_impl.h +++ b/content/renderer/pepper/pepper_plugin_delegate_impl.h @@ -318,7 +318,6 @@ class PepperPluginDelegateImpl virtual void DidStopLoading() OVERRIDE; virtual void SetContentRestriction(int restrictions) OVERRIDE; virtual void SaveURLAs(const GURL& url) OVERRIDE; - virtual double GetLocalTimeZoneOffset(base::Time t) OVERRIDE; virtual base::SharedMemory* CreateAnonymousSharedMemory(uint32_t size) OVERRIDE; virtual ::ppapi::Preferences GetPreferences() OVERRIDE; diff --git a/ppapi/proxy/flash_resource.cc b/ppapi/proxy/flash_resource.cc index be5acd3..176bd16 100644 --- a/ppapi/proxy/flash_resource.cc +++ b/ppapi/proxy/flash_resource.cc @@ -4,15 +4,42 @@ #include "ppapi/proxy/flash_resource.h" +#include <cmath> + +#include "base/containers/mru_cache.h" +#include "base/lazy_instance.h" +#include "base/time.h" #include "ppapi/c/pp_errors.h" #include "ppapi/c/private/ppb_flash.h" #include "ppapi/proxy/plugin_globals.h" #include "ppapi/proxy/ppapi_messages.h" +#include "ppapi/shared_impl/time_conversion.h" #include "ppapi/shared_impl/var.h" namespace ppapi { namespace proxy { +namespace { + +struct LocalTimeZoneOffsetEntry { + base::TimeTicks expiration; + double offset; +}; + +class LocalTimeZoneOffsetCache + : public base::MRUCache<PP_Time, LocalTimeZoneOffsetEntry> { + public: + LocalTimeZoneOffsetCache() + : base::MRUCache<PP_Time, LocalTimeZoneOffsetEntry>(kCacheSize) {} + private: + static const size_t kCacheSize = 100; +}; + +base::LazyInstance<LocalTimeZoneOffsetCache>::Leaky + g_local_time_zone_offset_cache = LAZY_INSTANCE_INITIALIZER; + +} // namespace + FlashResource::FlashResource(Connection connection, PP_Instance instance) : PluginResource(connection, instance) { SendCreate(RENDERER, PpapiHostMsg_Flash_Create()); @@ -56,5 +83,50 @@ PP_Bool FlashResource::SetCrashData(PP_Instance instance, return PP_FALSE; } +double FlashResource::GetLocalTimeZoneOffset(PP_Instance instance, + PP_Time t) { + LocalTimeZoneOffsetCache& cache = g_local_time_zone_offset_cache.Get(); + + // Get the minimum PP_Time value that shares the same minute as |t|. + // Use cached offset if cache hasn't expired and |t| is in the same minute as + // the time for the cached offset (assume offsets change on minute + // boundaries). + PP_Time t_minute_base = floor(t / 60.0) * 60.0; + LocalTimeZoneOffsetCache::iterator iter = cache.Get(t_minute_base); + base::TimeTicks now = base::TimeTicks::Now(); + if (iter != cache.end() && now < iter->second.expiration) + return iter->second.offset; + + // Cache the local offset for ten seconds, since it's slow on XP and Linux. + // Note that TimeTicks does not continue counting across sleep/resume on all + // platforms. This may be acceptable for 10 seconds, but if in the future this + // is changed to one minute or more, then we should consider using base::Time. + const int64 kMaxCachedLocalOffsetAgeInSeconds = 10; + base::TimeDelta expiration_delta = + base::TimeDelta::FromSeconds(kMaxCachedLocalOffsetAgeInSeconds); + + LocalTimeZoneOffsetEntry cache_entry; + cache_entry.expiration = now + expiration_delta; + cache_entry.offset = 0.0; + + // We can't do the conversion here on Linux because the localtime calls + // require filesystem access prohibited by the sandbox. + // TODO(shess): Figure out why OSX needs the access, the sandbox warmup should + // handle it. http://crbug.com/149006 +#if defined(OS_LINUX) || defined(OS_MACOSX) + int32_t result = SyncCall<PpapiPluginMsg_Flash_GetLocalTimeZoneOffsetReply>( + BROWSER, + PpapiHostMsg_Flash_GetLocalTimeZoneOffset(PPTimeToTime(t)), + &cache_entry.offset); + if (result != PP_OK) + cache_entry.offset = 0.0; +#else + cache_entry.offset = PPGetLocalTimeZoneOffset(PPTimeToTime(t)); +#endif + + cache.Put(t_minute_base, cache_entry); + return cache_entry.offset; +} + } // namespace proxy } // namespace ppapi diff --git a/ppapi/proxy/flash_resource.h b/ppapi/proxy/flash_resource.h index f970aed..3bd0734 100644 --- a/ppapi/proxy/flash_resource.h +++ b/ppapi/proxy/flash_resource.h @@ -33,6 +33,9 @@ class PPAPI_PROXY_EXPORT FlashResource virtual PP_Bool SetCrashData(PP_Instance instance, PP_FlashCrashKey key, PP_Var value) OVERRIDE; + virtual double GetLocalTimeZoneOffset(PP_Instance instance, + PP_Time t) OVERRIDE; + private: DISALLOW_COPY_AND_ASSIGN(FlashResource); }; diff --git a/ppapi/proxy/ppapi_messages.h b/ppapi/proxy/ppapi_messages.h index b6931cc..2a1cfb2 100644 --- a/ppapi/proxy/ppapi_messages.h +++ b/ppapi/proxy/ppapi_messages.h @@ -1601,6 +1601,13 @@ IPC_MESSAGE_CONTROL1(PpapiHostMsg_Flash_GetProxyForURL, std::string /* url */) IPC_MESSAGE_CONTROL1(PpapiPluginMsg_Flash_GetProxyForURLReply, std::string /* proxy */) +// Queries the browser for the local time zone offset for a given time. +IPC_MESSAGE_CONTROL1(PpapiHostMsg_Flash_GetLocalTimeZoneOffset, + base::Time /* time */) +// Reply to GetLocalTimeZoneOffset containing the time zone offset as a double. +IPC_MESSAGE_CONTROL1(PpapiPluginMsg_Flash_GetLocalTimeZoneOffsetReply, + double /* offset */) + // Device enumeration messages used by audio input and video capture. IPC_MESSAGE_CONTROL0(PpapiHostMsg_DeviceEnumeration_EnumerateDevices) IPC_MESSAGE_CONTROL1(PpapiPluginMsg_DeviceEnumeration_EnumerateDevicesReply, diff --git a/ppapi/proxy/ppb_flash_proxy.cc b/ppapi/proxy/ppb_flash_proxy.cc index 9e06ede..5eafabe 100644 --- a/ppapi/proxy/ppb_flash_proxy.cc +++ b/ppapi/proxy/ppb_flash_proxy.cc @@ -4,15 +4,10 @@ #include "ppapi/proxy/ppb_flash_proxy.h" -#include <math.h> - #include <limits> -#include "base/containers/mru_cache.h" -#include "base/lazy_instance.h" #include "base/logging.h" #include "base/message_loop.h" -#include "base/time.h" #include "build/build_config.h" #include "ppapi/c/dev/ppb_var_deprecated.h" #include "ppapi/c/pp_errors.h" @@ -31,7 +26,6 @@ #include "ppapi/shared_impl/resource.h" #include "ppapi/shared_impl/resource_tracker.h" #include "ppapi/shared_impl/scoped_pp_resource.h" -#include "ppapi/shared_impl/time_conversion.h" #include "ppapi/shared_impl/var.h" #include "ppapi/shared_impl/var_tracker.h" #include "ppapi/thunk/enter.h" @@ -47,23 +41,6 @@ namespace proxy { namespace { -struct LocalTimeZoneOffsetEntry { - base::TimeTicks expiration; - double offset; -}; - -class LocalTimeZoneOffsetCache - : public base::MRUCache<PP_Time, LocalTimeZoneOffsetEntry> { - public: - LocalTimeZoneOffsetCache() - : base::MRUCache<PP_Time, LocalTimeZoneOffsetEntry>(kCacheSize) {} - private: - static const size_t kCacheSize = 100; -}; - -base::LazyInstance<LocalTimeZoneOffsetCache>::Leaky - g_local_time_zone_offset_cache = LAZY_INSTANCE_INITIALIZER; - void InvokePrinting(PP_Instance instance) { ProxyAutoLock lock; @@ -105,8 +82,6 @@ bool PPB_Flash_Proxy::OnMessageReceived(const IPC::Message& msg) { IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_DrawGlyphs, OnHostMsgDrawGlyphs) IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_Navigate, OnHostMsgNavigate) - IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_GetLocalTimeZoneOffset, - OnHostMsgGetLocalTimeZoneOffset) IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_IsRectTopmost, OnHostMsgIsRectTopmost) IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_InvokePrinting, @@ -193,57 +168,6 @@ int32_t PPB_Flash_Proxy::Navigate(PP_Instance instance, return result; } -double PPB_Flash_Proxy::GetLocalTimeZoneOffset(PP_Instance instance, - PP_Time t) { - LocalTimeZoneOffsetCache& cache = g_local_time_zone_offset_cache.Get(); - - // Get the minimum PP_Time value that shares the same minute as |t|. - // Use cached offset if cache hasn't expired and |t| is in the same minute as - // the time for the cached offset (assume offsets change on minute - // boundaries). - PP_Time t_minute_base = floor(t / 60.0) * 60.0; - LocalTimeZoneOffsetCache::iterator iter = cache.Get(t_minute_base); - base::TimeTicks now = base::TimeTicks::Now(); - if (iter != cache.end() && now < iter->second.expiration) - return iter->second.offset; - - // Cache the local offset for ten seconds, since it's slow on XP and Linux. - // Note that TimeTicks does not continue counting across sleep/resume on all - // platforms. This may be acceptable for 10 seconds, but if in the future this - // is changed to one minute or more, then we should consider using base::Time. - const int64 kMaxCachedLocalOffsetAgeInSeconds = 10; - base::TimeDelta expiration_delta = - base::TimeDelta::FromSeconds(kMaxCachedLocalOffsetAgeInSeconds); - - LocalTimeZoneOffsetEntry cache_entry; - cache_entry.expiration = now + expiration_delta; - cache_entry.offset = 0.0; - - // TODO(shess): Figure out why OSX needs the access, the sandbox - // warmup should handle it. http://crbug.com/149006 -#if defined(OS_LINUX) || defined(OS_MACOSX) - // On Linux localtime needs access to the filesystem, which is prohibited - // by the sandbox. It would be better to go directly to the browser process - // for this message rather than proxy it through some instance in a renderer. - dispatcher()->Send(new PpapiHostMsg_PPBFlash_GetLocalTimeZoneOffset( - API_ID_PPB_FLASH, instance, t, &cache_entry.offset)); -#else - base::Time cur = PPTimeToTime(t); - base::Time::Exploded exploded = { 0 }; - base::Time::Exploded utc_exploded = { 0 }; - cur.LocalExplode(&exploded); - cur.UTCExplode(&utc_exploded); - if (exploded.HasValidValues() && utc_exploded.HasValidValues()) { - base::Time adj_time = base::Time::FromUTCExploded(exploded); - base::Time cur = base::Time::FromUTCExploded(utc_exploded); - cache_entry.offset = (adj_time - cur).InSecondsF(); - } -#endif - - cache.Put(t_minute_base, cache_entry); - return cache_entry.offset; -} - PP_Bool PPB_Flash_Proxy::IsRectTopmost(PP_Instance instance, const PP_Rect* rect) { PP_Bool result = PP_FALSE; @@ -348,18 +272,6 @@ void PPB_Flash_Proxy::OnHostMsgNavigate(PP_Instance instance, instance, data, target.c_str(), from_user_action); } -void PPB_Flash_Proxy::OnHostMsgGetLocalTimeZoneOffset(PP_Instance instance, - PP_Time t, - double* result) { - EnterInstanceNoLock enter(instance); - if (enter.succeeded()) { - *result = enter.functions()->GetFlashAPI()->GetLocalTimeZoneOffset( - instance, t); - } else { - *result = 0.0; - } -} - void PPB_Flash_Proxy::OnHostMsgIsRectTopmost(PP_Instance instance, PP_Rect rect, PP_Bool* result) { diff --git a/ppapi/proxy/ppb_flash_proxy.h b/ppapi/proxy/ppb_flash_proxy.h index 63cc506..a776d6a 100644 --- a/ppapi/proxy/ppb_flash_proxy.h +++ b/ppapi/proxy/ppb_flash_proxy.h @@ -11,7 +11,6 @@ #include "ppapi/c/pp_bool.h" #include "ppapi/c/pp_instance.h" #include "ppapi/c/pp_module.h" -#include "ppapi/c/pp_time.h" #include "ppapi/c/private/ppb_flash.h" #include "ppapi/proxy/interface_proxy.h" #include "ppapi/proxy/serialized_var.h" @@ -71,8 +70,6 @@ class PPB_Flash_Proxy : public InterfaceProxy, public thunk::PPB_Flash_API { const URLRequestInfoData& data, const char* target, PP_Bool from_user_action) OVERRIDE; - virtual double GetLocalTimeZoneOffset(PP_Instance instance, - PP_Time t) OVERRIDE; virtual PP_Bool IsRectTopmost(PP_Instance instance, const PP_Rect* rect) OVERRIDE; virtual PP_Var GetSetting(PP_Instance instance, @@ -92,8 +89,6 @@ class PPB_Flash_Proxy : public InterfaceProxy, public thunk::PPB_Flash_API { const std::string& target, PP_Bool from_user_action, int32_t* result); - void OnHostMsgGetLocalTimeZoneOffset(PP_Instance instance, PP_Time t, - double* result); void OnHostMsgIsRectTopmost(PP_Instance instance, PP_Rect rect, PP_Bool* result); diff --git a/ppapi/shared_impl/time_conversion.cc b/ppapi/shared_impl/time_conversion.cc index 07ca6f7..27ea494 100644 --- a/ppapi/shared_impl/time_conversion.cc +++ b/ppapi/shared_impl/time_conversion.cc @@ -52,4 +52,20 @@ double PPTimeTicksToEventTime(PP_TimeTicks t) { return t - GetTimeToTimeTicksDeltaInSeconds(); } +double PPGetLocalTimeZoneOffset(const base::Time& time) { + // Explode it to local time and then unexplode it as if it were UTC. Also + // explode it to UTC and unexplode it (this avoids mismatching rounding or + // lack thereof). The time zone offset is their difference. + base::Time::Exploded exploded = { 0 }; + base::Time::Exploded utc_exploded = { 0 }; + time.LocalExplode(&exploded); + time.UTCExplode(&utc_exploded); + if (exploded.HasValidValues() && utc_exploded.HasValidValues()) { + base::Time adj_time = base::Time::FromUTCExploded(exploded); + base::Time cur = base::Time::FromUTCExploded(utc_exploded); + return (adj_time - cur).InSecondsF(); + } + return 0.0; +} + } // namespace ppapi diff --git a/ppapi/shared_impl/time_conversion.h b/ppapi/shared_impl/time_conversion.h index 0acd39e..e20d809 100644 --- a/ppapi/shared_impl/time_conversion.h +++ b/ppapi/shared_impl/time_conversion.h @@ -23,6 +23,11 @@ PPAPI_SHARED_EXPORT PP_TimeTicks TimeTicksToPPTimeTicks(base::TimeTicks t); PPAPI_SHARED_EXPORT PP_TimeTicks EventTimeToPPTimeTicks(double event_time); PPAPI_SHARED_EXPORT double PPTimeTicksToEventTime(PP_TimeTicks t); +// Gets the local time zone offset for a given time. This works in the plugin +// process only on Windows (the sandbox prevents this from working properly on +// other platforms). +PPAPI_SHARED_EXPORT double PPGetLocalTimeZoneOffset(const base::Time& time); + } // namespace ppapi #endif // PPAPI_SHARED_IMPL_TIME_CONVERSION_H_ diff --git a/ppapi/thunk/ppb_flash_api.h b/ppapi/thunk/ppb_flash_api.h index d41acd9..4314550 100644 --- a/ppapi/thunk/ppb_flash_api.h +++ b/ppapi/thunk/ppb_flash_api.h @@ -54,7 +54,6 @@ class PPAPI_THUNK_EXPORT PPB_Flash_API { const char* target, PP_Bool from_user_action) = 0; - virtual double GetLocalTimeZoneOffset(PP_Instance instance, PP_Time t) = 0; virtual PP_Bool IsRectTopmost(PP_Instance instance, const PP_Rect* rect) = 0; virtual PP_Var GetSetting(PP_Instance instance, PP_FlashSetting setting) = 0; }; diff --git a/ppapi/thunk/ppb_flash_functions_api.h b/ppapi/thunk/ppb_flash_functions_api.h index 4aa3fec..69f50108 100644 --- a/ppapi/thunk/ppb_flash_functions_api.h +++ b/ppapi/thunk/ppb_flash_functions_api.h @@ -27,6 +27,7 @@ class PPAPI_THUNK_EXPORT PPB_Flash_Functions_API { virtual PP_Bool SetCrashData(PP_Instance instance, PP_FlashCrashKey key, PP_Var value) = 0; + virtual double GetLocalTimeZoneOffset(PP_Instance instance, PP_Time t) = 0; static const SingletonResourceID kSingletonResourceID = FLASH_SINGLETON_ID; }; diff --git a/ppapi/thunk/ppb_flash_thunk.cc b/ppapi/thunk/ppb_flash_thunk.cc index 9aac0ac..1f809eb 100644 --- a/ppapi/thunk/ppb_flash_thunk.cc +++ b/ppapi/thunk/ppb_flash_thunk.cc @@ -87,10 +87,10 @@ void QuitMessageLoop(PP_Instance instance) { } double GetLocalTimeZoneOffset(PP_Instance instance, PP_Time t) { - EnterInstance enter(instance); + EnterInstanceAPI<PPB_Flash_Functions_API> enter(instance); if (enter.failed()) return 0.0; - return enter.functions()->GetFlashAPI()->GetLocalTimeZoneOffset(instance, t); + return enter.functions()->GetLocalTimeZoneOffset(instance, t); } PP_Var GetCommandLineArgs(PP_Module /* pp_module */) { diff --git a/webkit/plugins/ppapi/mock_plugin_delegate.cc b/webkit/plugins/ppapi/mock_plugin_delegate.cc index eec48da..8339ac4 100644 --- a/webkit/plugins/ppapi/mock_plugin_delegate.cc +++ b/webkit/plugins/ppapi/mock_plugin_delegate.cc @@ -371,10 +371,6 @@ void MockPluginDelegate::SetContentRestriction(int restrictions) { void MockPluginDelegate::SaveURLAs(const GURL& url) { } -double MockPluginDelegate::GetLocalTimeZoneOffset(base::Time t) { - return 0.0; -} - base::SharedMemory* MockPluginDelegate::CreateAnonymousSharedMemory( uint32_t size) { return NULL; diff --git a/webkit/plugins/ppapi/mock_plugin_delegate.h b/webkit/plugins/ppapi/mock_plugin_delegate.h index f2f3407..fdd8bf2 100644 --- a/webkit/plugins/ppapi/mock_plugin_delegate.h +++ b/webkit/plugins/ppapi/mock_plugin_delegate.h @@ -170,7 +170,6 @@ class MockPluginDelegate : public PluginDelegate { virtual void DidStopLoading(); virtual void SetContentRestriction(int restrictions); virtual void SaveURLAs(const GURL& url); - virtual double GetLocalTimeZoneOffset(base::Time t); virtual base::SharedMemory* CreateAnonymousSharedMemory(uint32_t size); virtual ::ppapi::Preferences GetPreferences(); virtual bool LockMouse(PluginInstance* instance); diff --git a/webkit/plugins/ppapi/plugin_delegate.h b/webkit/plugins/ppapi/plugin_delegate.h index 9c22ce9..b228cf3 100644 --- a/webkit/plugins/ppapi/plugin_delegate.h +++ b/webkit/plugins/ppapi/plugin_delegate.h @@ -616,8 +616,6 @@ class PluginDelegate { // Tells the browser to bring up SaveAs dialog to save specified URL. virtual void SaveURLAs(const GURL& url) = 0; - virtual double GetLocalTimeZoneOffset(base::Time t) = 0; - // Create an anonymous shared memory segment of size |size| bytes, and return // a pointer to it, or NULL on error. Caller owns the returned pointer. virtual base::SharedMemory* CreateAnonymousSharedMemory(uint32_t size) = 0; diff --git a/webkit/plugins/ppapi/ppb_flash_impl.cc b/webkit/plugins/ppapi/ppb_flash_impl.cc index f278473..43e9ba2 100644 --- a/webkit/plugins/ppapi/ppb_flash_impl.cc +++ b/webkit/plugins/ppapi/ppb_flash_impl.cc @@ -168,21 +168,6 @@ int32_t PPB_Flash_Impl::Navigate(PP_Instance instance, return instance_->Navigate(data, target, PP_ToBool(from_user_action)); } -double PPB_Flash_Impl::GetLocalTimeZoneOffset(PP_Instance instance, - PP_Time t) { - // Evil hack. The time code handles exact "0" values as special, and produces - // a "null" Time object. This will represent some date hundreds of years ago - // and will give us funny results at 1970 (there are some tests where this - // comes up, but it shouldn't happen in real life). To work around this - // special handling, we just need to give it some nonzero value. - if (t == 0.0) - t = 0.0000000001; - - // We can't do the conversion here because on Linux, the localtime calls - // require filesystem access prohibited by the sandbox. - return instance_->delegate()->GetLocalTimeZoneOffset(PPTimeToTime(t)); -} - PP_Bool PPB_Flash_Impl::IsRectTopmost(PP_Instance instance, const PP_Rect* rect) { return PP_FromBool(instance_->IsRectTopmost( diff --git a/webkit/plugins/ppapi/ppb_flash_impl.h b/webkit/plugins/ppapi/ppb_flash_impl.h index 68ff0d8..34ed979 100644 --- a/webkit/plugins/ppapi/ppb_flash_impl.h +++ b/webkit/plugins/ppapi/ppb_flash_impl.h @@ -44,8 +44,6 @@ class PPB_Flash_Impl : public ::ppapi::thunk::PPB_Flash_API { const ::ppapi::URLRequestInfoData& data, const char* target, PP_Bool from_user_action) OVERRIDE; - virtual double GetLocalTimeZoneOffset(PP_Instance instance, - PP_Time t) OVERRIDE; virtual PP_Bool IsRectTopmost(PP_Instance instance, const PP_Rect* rect) OVERRIDE; virtual PP_Var GetSetting(PP_Instance instance, |