private static string GetScreenPixelsWidth(DeviceInfo device) { return(Strings.Get(device.GetCapability(ResolutionWidth))); }
private static string GetSupportsAccesskeyAttribute(DeviceInfo device) { return(Strings.Get(device.GetCapability(AccessKeySupport))); }
/// <summary> /// Updates the capabilities used by Microsoft's implementation of the /// HttpBrowserCapabilities class to control the property values it /// returns. Only properties exposed by FiftyOneBrowserCapabilities are overriden /// by this method. /// </summary> /// <param name="capabilities">Dictionary of capabilities to be enhanced.</param> /// <param name="currentCapabilities">Dictionary of existing capabilities for the device.</param> /// <param name="device">Device to use for enhancements.</param> private static void Enhance(IDictionary capabilities, IDictionary currentCapabilities, DeviceInfo device) { // Set base capabilities for all mobile devices. SetStaticValues(capabilities); SetValue(capabilities, "actualDeviceRoot", device.IsActualDeviceRoot.ToString()); SetValue(capabilities, "isMobileDevice", GetIsMobileDevice(device)); SetValue(capabilities, "crawler", GetIsCrawler(device)); SetValue(capabilities, "mobileDeviceModel", GetMobileDeviceModel(device)); SetValue(capabilities, "mobileDeviceManufacturer", GetMobileDeviceManufacturer(device)); SetValue(capabilities, "platform", GetPlatform(device)); SetValue(capabilities, "type", capabilities["mobileDeviceManufacturer"]); SetValue(capabilities, "supportsAccessKeyAttribute", GetSupportsAccesskeyAttribute(device)); SetValue(capabilities, "hasBackButton", GetHasBackButton(device)); SetValue(capabilities, "screenPixelsHeight", GetScreenPixelsHeight(device)); SetValue(capabilities, "screenPixelsWidth", GetScreenPixelsWidth(device)); SetValue(capabilities, "screenBitDepth", GetScreenBitDepth(device)); SetValue(capabilities, "preferredImageMime", GetPreferredImageMime(device, capabilities)); SetValue(capabilities, "isColor", GetIsColor(device)); SetValue(capabilities, "SupportsCallback", GetSupportsCallback(device)); SetValue(capabilities, "maximumRenderedPageSize", GetMaximumRenderedPageSize(device)); SetValue(capabilities, "rendersBreaksAfterWmlAnchor", GetRendersBreaksAfterWmlAnchor(device)); SetValue(capabilities, "rendersBreaksAfterWmlInput", GetRendersBreaksAfterWmlInput(device)); SetValue(capabilities, "screenCharactersHeight", GetScreenCharactersHeight(device)); SetValue(capabilities, "screenCharactersWidth", GetScreenCharactersWidth(device)); SetValue(capabilities, "requiresUTF8ContentEncoding", GetRequiresUTF8ContentEncoding(device)); SetValue(capabilities, "tables", GetTables(device)); SetValue(capabilities, "canInitiateVoiceCall", GetIsMobileDevice(device)); SetValue(capabilities, "javascript", GetJavascriptSupport(device)); SetValue(capabilities, "supportsNoWrapStyle", GetSupportsNoWrapStyle(device)); SetValue(capabilities, "supportsStyleElement", GetPreferredRenderingTypeFromWURFL(device)); SetValue(capabilities, "maximumSoftKeyLabelLength", GetMaximumSoftKeyLabelLength(device)); // Use the Version class to find the version. If this fails use the 1st two // decimal segments of the string. string versionString = Strings.Get(device.GetCapability(MobileBrowserVersion)); if (String.IsNullOrEmpty(versionString) == false) { try { Version version = new Version(versionString); SetValue(capabilities, "majorversion", version.Major.ToString()); SetValue(capabilities, "minorversion", "." + version.Minor.ToString()); SetValue(capabilities, "version", version.ToString()); } catch (FormatException) { SetVersion(capabilities, versionString); } catch (ArgumentException) { SetVersion(capabilities, versionString); } } else { // Ensure the version values are not null to prevent null arguement exceptions // with some controls. versionString = currentCapabilities != null ? currentCapabilities["version"] as string : "0.0"; SetVersion(capabilities, versionString); } SetValue(capabilities, "supportsImageSubmit", GetSupportsImageSubmit(device)); // All we can determine from WURFL is if javascript is supported as a boolean. // Use this value to set a version number that is the same for all devices that // indicate javascript support. bool javaScript = GetJavascriptSupport(device); SetJavaScript(capabilities, javaScript); SetValue(capabilities, "ecmascriptversion", javaScript ? "3.0" : "0.0"); SetValue(capabilities, "jscriptversion", javaScript ? "5.7" : "0.0"); SetValue(capabilities, "w3cdomversion", GetW3CDOMVersion(device, currentCapabilities != null ? (string)currentCapabilities["w3cdomversion"] : String.Empty)); SetValue(capabilities, "cookies", GetCookieSupport(device, currentCapabilities != null ? (string)currentCapabilities["cookies"] : String.Empty)); // Only set these values from WURFL if they've not already been set from // the Http request header. if (capabilities.Contains("preferredRenderingType") == false) { // Set the rendering type for the response. string renderingType = GetPreferredRenderingTypeFromWURFL(device); if (String.IsNullOrEmpty(renderingType) == false) { SetValue(capabilities, "preferredRenderingType", renderingType); } // Set the Mime type of the response. if (capabilities.Contains("preferredRenderingMime") == false) { string renderingMime = GetPreferredRenderingMimeFromWURFL(device, renderingType); if (String.IsNullOrEmpty(renderingMime) == false) { SetValue(capabilities, "preferredRenderingMime", renderingMime); } } } }
private static string GetAdapters(DeviceInfo device) { return(Strings.Get(device.GetCapability(Adapters))); }
/// <summary> /// Creates an instance of DeviceInfo. /// </summary> /// <param name="userAgent">User agent string used to identify this device.</param> /// <param name="deviceId">A unique Identifier of the device.</param> /// <param name="devices">A reference to the complete index of devices.</param> /// <param name="fallbackDevice">The fallback device to use for this device if any.</param> internal DeviceInfo( Provider devices, string deviceId, string userAgent, DeviceInfo fallbackDevice) { if (fallbackDevice == null) throw new ArgumentNullException("fallbackDevice"); Init(devices, deviceId, userAgent); _fallbackDevice = fallbackDevice; }
private static string GetTables(DeviceInfo device) { string value = Strings.Get(device.GetCapability(XhtmlTableSupport)); if(String.IsNullOrEmpty(value) || value.Equals("false", StringComparison.InvariantCultureIgnoreCase)) return bool.FalseString.ToLowerInvariant(); return bool.TrueString.ToLowerInvariant(); }
private static string GetPlatform(DeviceInfo device) { return Strings.Get(device.GetCapability(DeviceOs)); }
/// <summary> /// Loops through the fallback devices until an actual device root is found. /// </summary> /// <param name="device">The device to be checked.</param> /// <returns>A device that is a root.</returns> private DeviceInfo GetActualDeviceRootDeviceInfo(DeviceInfo device) { DeviceInfo fallback = device.FallbackDevice; if (fallback != null) { if (fallback.IsActualDeviceRoot) return fallback; else return GetActualDeviceRootDeviceInfo(fallback); } return null; }
private static string GetMobileDeviceManufacturer(DeviceInfo device) { return Strings.Get(device.GetCapability(BrandName)); }
private static string GetMobileDeviceModel(DeviceInfo device) { string value = Strings.Get(device.GetCapability(MarketingName)); if (String.IsNullOrEmpty(value)) value = Strings.Get(device.GetCapability(ModelName)); return value; }
//The following methods and bindings were suggested by forum member 'fravelgue' private static string GetMaximumSoftKeyLabelLength(DeviceInfo device) { string value = Strings.Get(device.GetCapability(SoftkeySupport)); if (String.IsNullOrEmpty(value) || value.Equals("false", StringComparison.InvariantCultureIgnoreCase)) return bool.FalseString.ToLowerInvariant(); return bool.TrueString.ToLowerInvariant(); }
private static string GetMaximumRenderedPageSize(DeviceInfo device) { return Strings.Get(device.GetCapability(MaxDeckSize)); }
/// <summary> /// If the wurfl database indicates javascript support then return true. /// </summary> /// <param name="device">The device to be checked.</param> /// <returns>True if javascript is supported.</returns> private static bool GetJavascriptSupport(DeviceInfo device) { bool java = false; if (bool.TryParse(Strings.Get(device.GetCapability(AjaxSupportJavascript)), out java) && java) { return true; } return false; }
private static string GetScreenCharactersWidth(DeviceInfo device) { return(Strings.Get(device.GetCapability(Columns))); }
private static string GetPreferredImageMime(DeviceInfo device, IDictionary capabilities) { // Look at the database and return the 1st one that matches in order // of preference. if (bool.TrueString.Equals(Strings.Get(device.GetCapability(Png)), StringComparison.InvariantCultureIgnoreCase)) return "image/png"; if (bool.TrueString.Equals(Strings.Get(device.GetCapability(Jpg)), StringComparison.InvariantCultureIgnoreCase)) return "image/jpeg"; if (bool.TrueString.Equals(Strings.Get(device.GetCapability(Gif)), StringComparison.InvariantCultureIgnoreCase)) return "image/gif"; return null; }
private static string GetMaximumRenderedPageSize(DeviceInfo device) { return(Strings.Get(device.GetCapability(MaxDeckSize))); }
private static string GetPreferredRenderingMimeFromWURFL(DeviceInfo device, string renderingType) { switch (renderingType) { case "xhtml-mp": case "xhtml-basic": return Strings.Get(device.GetCapability(XhtmlmpPreferredMimeType)); case "chtml10": case "html4": case "html32": return "text/html"; default: return null; } }
private static void LoadCapabilityData( XmlReader reader, DeviceInfo device, StringCollection availableCapabilities) { string capabilityName = reader.GetAttribute(Constants.NameAttributeName, string.Empty); // If it is not white listed, do not load into the memory. // This is to keep memory consumption down. if (_loadOnlyCapabilitiesWhiteListed && _capabilitiesWhiteListed.Contains(capabilityName) == false) return; string capabilityValue = reader.GetAttribute(Constants.ValueAttributeName, string.Empty); // Store all the capabilities names, that's used to make sure // all devices has all capabilities associated to it. if (availableCapabilities.Contains(capabilityName) == false) availableCapabilities.Add(capabilityName); // Ensure the capability is set to the current value. device.Capabilities.Set(capabilityName, capabilityValue); }
private static string GetPreferredRenderingTypeFromWURFL(DeviceInfo device) { switch (Strings.Get(device.GetCapability(PreferredMarkup))) { case "html_web_3_2": return "html32"; case "html_web_4_0": return "html4"; case "html_wi_oma_xhtmlmp_1_0": return "xhtml-mp"; case "html_wi_w3_xhtmlbasic": return "xhtml-basic"; case "html_wi_imode_htmlx_1": case "html_wi_imode_html_1": case "html_wi_imode_html_2": case "html_wi_imode_html_3": case "html_wi_imode_html_4": case "html_wi_imode_html_5": case "html_wi_imode_html_6": case "html_wi_imode_htmlx_1_1": case "html_wi_imode_compact_generic": return "chtml10"; default: return GetFirstRenderingTypeFromWURFL(device); } }
private static string GetIsMobileDevice(DeviceInfo device) { if (device.IsMobileDevice) return bool.TrueString.ToLowerInvariant(); return bool.FalseString.ToLowerInvariant(); }
private static string GetRendersBreaksAfterWmlInput(DeviceInfo device) { string value = Strings.Get(device.GetCapability(InsertBrElementAfterWidgetRecommended)); if (String.IsNullOrEmpty(value) || value.Equals("false", StringComparison.InvariantCultureIgnoreCase)) return bool.FalseString.ToLowerInvariant(); return bool.TrueString.ToLowerInvariant(); }
private static string GetW3CDOMVersion(DeviceInfo device, string current) { int level = 0; Version version = new Version(0, 0); if (int.TryParse(Strings.Get(device.GetCapability(XhtmlSupportLevel)), out level) && level >= 4) version = new Version("1.0.0.0"); else { try { version = new Version(current); } catch (ArgumentException) { // Do nothing and let the default value be returned. } } return version.ToString(2); }
private static string GetRequiresUTF8ContentEncoding(DeviceInfo device) { string value = Strings.Get(device.GetCapability(Utf8Support)); if (String.IsNullOrEmpty(value) || value.Equals("false", StringComparison.InvariantCultureIgnoreCase)) return bool.FalseString.ToLowerInvariant(); return bool.TrueString.ToLowerInvariant(); }
private static string GetPlatform(DeviceInfo device) { return(Strings.Get(device.GetCapability(DeviceOs))); }
private static string GetScreenBitDepth(DeviceInfo device) { long fScreenBitDepth = 1; long numberOfColors = 256; long.TryParse(Strings.Get(device.GetCapability(Colors)), out numberOfColors); fScreenBitDepth = Support.GetBitsPerPixel(numberOfColors); return fScreenBitDepth.ToString(CultureInfo.InvariantCulture); }
private static string GetScreenPixelsHeight(DeviceInfo device) { return(Strings.Get(device.GetCapability(ResolutionHeight))); }
private static string GetScreenCharactersHeight(DeviceInfo device) { return Strings.Get(device.GetCapability(Rows)); }
private static string GetHasBackButton(DeviceInfo device) { return(Strings.Get(device.GetCapability(BuiltInBackButtonSupport))); }
private static string GetScreenCharactersWidth(DeviceInfo device) { return Strings.Get(device.GetCapability(Columns)); }
private static string GetMobileDeviceManufacturer(DeviceInfo device) { return(Strings.Get(device.GetCapability(BrandName))); }
private static string GetScreenPixelsHeight(DeviceInfo device) { return Strings.Get(device.GetCapability(ResolutionHeight)); }
private static string GetScreenCharactersHeight(DeviceInfo device) { return(Strings.Get(device.GetCapability(Rows))); }
private static string GetScreenPixelsWidth(DeviceInfo device) { return Strings.Get(device.GetCapability(ResolutionWidth)); }
/// <summary> /// Records the device in the indexes used by the API. If a device /// with the same ID already exists the previous one is overwritten. /// The device is also assigned to a handler based on the useragent, /// and supported root devices of the handler. /// </summary> /// <param name="device">The new device being added.</param> internal void Set(DeviceInfo device) { // Does the device already exist? lock (_deviceIDs) { if (_deviceIDs.ContainsKey(device.DeviceId)) { // Yes. Replace the previous device as it's likely this new // one is coming from a more current source. _deviceIDs[device.DeviceId] = device; } else { // No. So add the new device. _deviceIDs.Add(device.DeviceId, device); } } // Add the new device to handlers that can support it. if (String.IsNullOrEmpty(device.UserAgent) == false) { #if VER4 foreach (Handler handler in GetHandlers(device).Where(handler => handler != null)) { handler.Set(device); } #elif VER2 foreach (Handler handler in GetHandlers(device)) if (handler != null) handler.Set(device); #endif } }
private static string GetSupportsAccesskeyAttribute(DeviceInfo device) { return Strings.Get(device.GetCapability(AccessKeySupport)); }
/// <summary> /// Gets an array of handlers that will support the device information. /// Device ids are used to determine if the handler supports the device /// tree the requested device is within. /// </summary> /// <param name="device">Device information to find supporting handlers.</param> /// <returns>A list of all handlers that can handle this device.</returns> private Handler[] GetHandlers(DeviceInfo device) { byte highestConfidence = 0; List<Handler> handlers = new List<Handler>(); #if VER4 foreach (Handler handler in _handlers.Where(handler => handler.CanHandle(device))) { GetHandlers(ref highestConfidence, handlers, handler); } #elif VER2 foreach (Handler handler in _handlers) { if (handler.CanHandle(device)) GetHandlers(ref highestConfidence, handlers, handler); } #endif return handlers.ToArray(); }
/// <summary> /// Returns true if the device supports callbacks from the browser /// using XMLHttpRequest using any type of method. /// </summary> /// <param name="device">The device to be checked.</param> /// <returns>True if XMLHttpRequest is supported.</returns> private static string GetSupportsCallback(DeviceInfo device) { string value = Strings.Get(device.GetCapability(AjaxXhrType)); if (String.IsNullOrEmpty(value) || value.Equals("none", StringComparison.InvariantCultureIgnoreCase)) return bool.FalseString.ToLowerInvariant(); return bool.TrueString.ToLowerInvariant(); }
/// <summary> /// Processes the XML element containing the device attributes. /// </summary> /// <param name="devices">A list of loaded devices.</param> /// <param name="reader">The XML stream readers.</param> /// <returns>An empty device.</returns> private static DeviceInfo LoadDevice(Provider devices, XmlReader reader) { // Create the next device using the fallback device if available. string deviceId = reader.GetAttribute(Constants.IdAttributeName, string.Empty); string userAgent = reader.GetAttribute(Constants.UserAgentAttributeName, string.Empty); string fallbackDeviceId = reader.GetAttribute(Constants.FallbackAttributeName, string.Empty); // If the device already exists then use the previous one. This may happen // when an earlier device referenced a fallback device that had not yet // been created. DeviceInfo device = devices.GetDeviceInfoFromID(deviceId); if (device == null) { // Create the new device. device = new DeviceInfo(devices, deviceId, userAgent ?? String.Empty); } else if (userAgent != null) { // Ensure the correct UserAgent string is assigned to this device. device.SetUserAgent(userAgent); } // If the Actual Device Root attribute is specified then set the value // for this device. bool isActualDeviceRoot; if (bool.TryParse(reader.GetAttribute(Constants.ActualDeviceRoot, string.Empty), out isActualDeviceRoot)) device.IsActualDeviceRoot = isActualDeviceRoot; // Check the fallback device is different to the device being loaded. if (fallbackDeviceId != null && device.DeviceId != fallbackDeviceId) { // Does the fallback device already exist? device.FallbackDevice = devices.GetDeviceInfoFromID(fallbackDeviceId); if (device.FallbackDevice == null) { // No. So create new fallback device. device.FallbackDevice = new DeviceInfo(devices, fallbackDeviceId); // Add it to the available devices. devices.Set(device.FallbackDevice); } } return device; }
private static string GetSupportsImageSubmit(DeviceInfo device) { int value = 0; if (int.TryParse(Strings.Get(device.GetCapability(XhtmlSupportLevel)), out value) && value >= 3) return bool.TrueString.ToLowerInvariant(); return bool.FalseString.ToLowerInvariant(); }
/// <summary> /// Creates a new device using the source device as the fallback. /// </summary> /// <param name="source">Source device for the new device.</param> /// <param name="deviceId">Id of the new device.</param> internal DeviceInfo(DeviceInfo source, string deviceId) : this(source._devices, deviceId, source._userAgent, source) { }
private static string GetIsCrawler(DeviceInfo device) { if (device.DeviceId == "generic_web_crawler" || device.DeviceId.Contains("crawler")) return bool.TrueString.ToLowerInvariant(); ; if (device.FallbackDevice != null) return GetIsCrawler(device.FallbackDevice); return bool.FalseString.ToLowerInvariant(); ; }