* @param configuration the protocol configuration.
*/
private void initialiseDeviceProtocolConfiguration(
InternalDevice device, ProtocolConfiguration configuration) {
ProtocolConfigurationImpl config = (ProtocolConfigurationImpl)
configuration;
boolean supportsJavascript = device.getBooleanPolicyValue(
DevicePolicyConstants.SUPPORTS_JAVASCRIPT);
config.setCanSupportJavaScript(supportsJavascript);
try {
int devicePixelsX;
devicePixelsX = device.getIntegerPolicyValue(
DevicePolicyConstants.USABLE_WIDTH_IN_PIXELS);
config.setDevicePixelsX(devicePixelsX);
} catch(NumberFormatException e){
// default value will be used.
}
// Version of CFW since the device is supported
String since = device.getPolicyValue(
DevicePolicyConstants.SUPPORTS_VFC_SINCE);
if (since == null) {
since = DevicePolicyConstants.SUPPORTS_VFC_SINCE_DEFAULT;
}
config.setFrameworkClientSupportedSince(since);
// Whether the device has viewport support
String viewportVirtualSupport = device.getPolicyValue(
DevicePolicyConstants.X_BROWSER_VIEWPORT_VIRTUAL_SUPPORT);
config.setViewportVirtualSupport(viewportVirtualSupport);
// Framework Client support configuration
config.setFrameworkClientSupported(configurePolicyValue(
device,
DevicePolicyConstants.SUPPORTS_VFC,
DevicePolicyConstants.SUPPORTS_VFC_DEFAULT,
config.getFrameworkClientSupported()));
// todo: later: configurators should be registered externally (for testing)
// todo: later: create a ProtocolBuilderFactory to pass in dependencies.
CSSConfigurator cssConfigurator = new CSSConfigurator();
cssConfigurator.initialise(config, device);
// ???else, test cases with null device assume no javascript support???
// else, the device is null. Currently this may happen for
// integration test cases but in future we should avoid this.
// todo: integration test cases to provide non-null device here.
// Complete the configuration initialisation now that the css version
// has been initialised (do this before a default version is supplied
// if it's null). This must be done even if the device is null to
// ensure that everything is initialised (even if empty).
DeviceCapabilityManagerBuilder builder =
new DeviceCapabilityManagerBuilder(device);
config.initialize(device, builder);
// If we did not try and set the CSS or we did but no CSS was found,
// then we will have a null CSS version. This should only ever happen
// in testing, but means that all the subsequent code must check for
// null, which is very tedious. Instead we sub in a testing CSS version
// which prevents us having to do this.
if (config.getCssVersion() == null) {
// assume the most common case for test cases for now.
DefaultCSSVersion cssVersion =
new ManualCSS2VersionFactory().createCSSVersion();
cssVersion.markImmutable();
config.setCssVersion(cssVersion);
if (logger.isDebugEnabled()) {
logger.debug("Using testing base CSS Version: " +
configuration.getCssVersion());
}
}
ExtractorConfigurator configurator = new ExtractorConfigurator();
ExtractorConfiguration extractor =
configurator.createConfiguration(device,
configuration.getCssVersion());
config.setExtractorConfiguration(extractor);
// CSS media
String media = device.getPolicyValue(DevicePolicyConstants.CSS_MEDIA_SUPPORTED);
// If media is specified (not null and not empty),
// set the value on protocol.
if ((media != null) && !media.equals("")) {
config.setCSSMedia(media);
}
}