| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ppapi/proxy/flash_resource.h" | 5 #include "ppapi/proxy/flash_resource.h" |
| 6 | 6 |
| 7 #include <cmath> | 7 #include <cmath> |
| 8 | 8 |
| 9 #include "base/containers/mru_cache.h" | 9 #include "base/containers/mru_cache.h" |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| 11 #include "base/time.h" | 11 #include "base/time.h" |
| 12 #include "ppapi/c/pp_errors.h" | 12 #include "ppapi/c/pp_errors.h" |
| 13 #include "ppapi/c/private/ppb_flash.h" | 13 #include "ppapi/c/private/ppb_flash.h" |
| 14 #include "ppapi/proxy/plugin_dispatcher.h" |
| 14 #include "ppapi/proxy/plugin_globals.h" | 15 #include "ppapi/proxy/plugin_globals.h" |
| 15 #include "ppapi/proxy/ppapi_messages.h" | 16 #include "ppapi/proxy/ppapi_messages.h" |
| 17 #include "ppapi/shared_impl/ppapi_preferences.h" |
| 18 #include "ppapi/shared_impl/scoped_pp_var.h" |
| 16 #include "ppapi/shared_impl/time_conversion.h" | 19 #include "ppapi/shared_impl/time_conversion.h" |
| 17 #include "ppapi/shared_impl/var.h" | 20 #include "ppapi/shared_impl/var.h" |
| 21 #include "ppapi/thunk/enter.h" |
| 18 | 22 |
| 19 namespace ppapi { | 23 namespace ppapi { |
| 20 namespace proxy { | 24 namespace proxy { |
| 21 | 25 |
| 22 namespace { | 26 namespace { |
| 23 | 27 |
| 24 struct LocalTimeZoneOffsetEntry { | 28 struct LocalTimeZoneOffsetEntry { |
| 25 base::TimeTicks expiration; | 29 base::TimeTicks expiration; |
| 26 double offset; | 30 double offset; |
| 27 }; | 31 }; |
| 28 | 32 |
| 29 class LocalTimeZoneOffsetCache | 33 class LocalTimeZoneOffsetCache |
| 30 : public base::MRUCache<PP_Time, LocalTimeZoneOffsetEntry> { | 34 : public base::MRUCache<PP_Time, LocalTimeZoneOffsetEntry> { |
| 31 public: | 35 public: |
| 32 LocalTimeZoneOffsetCache() | 36 LocalTimeZoneOffsetCache() |
| 33 : base::MRUCache<PP_Time, LocalTimeZoneOffsetEntry>(kCacheSize) {} | 37 : base::MRUCache<PP_Time, LocalTimeZoneOffsetEntry>(kCacheSize) {} |
| 34 private: | 38 private: |
| 35 static const size_t kCacheSize = 100; | 39 static const size_t kCacheSize = 100; |
| 36 }; | 40 }; |
| 37 | 41 |
| 38 base::LazyInstance<LocalTimeZoneOffsetCache>::Leaky | 42 base::LazyInstance<LocalTimeZoneOffsetCache>::Leaky |
| 39 g_local_time_zone_offset_cache = LAZY_INSTANCE_INITIALIZER; | 43 g_local_time_zone_offset_cache = LAZY_INSTANCE_INITIALIZER; |
| 40 | 44 |
| 41 } // namespace | 45 } // namespace |
| 42 | 46 |
| 43 FlashResource::FlashResource(Connection connection, PP_Instance instance) | 47 FlashResource::FlashResource(Connection connection, |
| 44 : PluginResource(connection, instance) { | 48 PP_Instance instance, |
| 49 PluginDispatcher* plugin_dispatcher) |
| 50 : PluginResource(connection, instance), |
| 51 plugin_dispatcher_(plugin_dispatcher) { |
| 45 SendCreate(RENDERER, PpapiHostMsg_Flash_Create()); | 52 SendCreate(RENDERER, PpapiHostMsg_Flash_Create()); |
| 46 SendCreate(BROWSER, PpapiHostMsg_Flash_Create()); | 53 SendCreate(BROWSER, PpapiHostMsg_Flash_Create()); |
| 47 } | 54 } |
| 48 | 55 |
| 49 FlashResource::~FlashResource() { | 56 FlashResource::~FlashResource() { |
| 50 } | 57 } |
| 51 | 58 |
| 52 thunk::PPB_Flash_Functions_API* FlashResource::AsPPB_Flash_Functions_API() { | 59 thunk::PPB_Flash_Functions_API* FlashResource::AsPPB_Flash_Functions_API() { |
| 53 return this; | 60 return this; |
| 54 } | 61 } |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 if (result != PP_OK) | 128 if (result != PP_OK) |
| 122 cache_entry.offset = 0.0; | 129 cache_entry.offset = 0.0; |
| 123 #else | 130 #else |
| 124 cache_entry.offset = PPGetLocalTimeZoneOffset(PPTimeToTime(t)); | 131 cache_entry.offset = PPGetLocalTimeZoneOffset(PPTimeToTime(t)); |
| 125 #endif | 132 #endif |
| 126 | 133 |
| 127 cache.Put(t_minute_base, cache_entry); | 134 cache.Put(t_minute_base, cache_entry); |
| 128 return cache_entry.offset; | 135 return cache_entry.offset; |
| 129 } | 136 } |
| 130 | 137 |
| 138 PP_Var FlashResource::GetSetting(PP_Instance instance, |
| 139 PP_FlashSetting setting) { |
| 140 switch (setting) { |
| 141 case PP_FLASHSETTING_3DENABLED: |
| 142 return PP_MakeBool(PP_FromBool( |
| 143 plugin_dispatcher_->preferences().is_3d_supported)); |
| 144 case PP_FLASHSETTING_INCOGNITO: |
| 145 return PP_MakeBool(PP_FromBool(plugin_dispatcher_->incognito())); |
| 146 case PP_FLASHSETTING_STAGE3DENABLED: |
| 147 return PP_MakeBool(PP_FromBool( |
| 148 plugin_dispatcher_->preferences().is_stage3d_supported)); |
| 149 case PP_FLASHSETTING_LANGUAGE: |
| 150 return StringVar::StringToPPVar( |
| 151 PluginGlobals::Get()->GetUILanguage()); |
| 152 case PP_FLASHSETTING_NUMCORES: |
| 153 return PP_MakeInt32( |
| 154 plugin_dispatcher_->preferences().number_of_cpu_cores); |
| 155 case PP_FLASHSETTING_LSORESTRICTIONS: { |
| 156 int32_t restrictions; |
| 157 int32_t result = |
| 158 SyncCall<PpapiPluginMsg_Flash_GetLocalDataRestrictionsReply>(BROWSER, |
| 159 PpapiHostMsg_Flash_GetLocalDataRestrictions(), &restrictions); |
| 160 if (result != PP_OK) |
| 161 return PP_MakeInt32(PP_FLASHLSORESTRICTIONS_NONE); |
| 162 return PP_MakeInt32(restrictions); |
| 163 } |
| 164 } |
| 165 return PP_MakeUndefined(); |
| 166 } |
| 167 |
| 131 } // namespace proxy | 168 } // namespace proxy |
| 132 } // namespace ppapi | 169 } // namespace ppapi |
| OLD | NEW |