You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ApplicationConfiguration.java 28KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817
  1. /*
  2. * Copyright 2000-2013 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.client;
  17. import java.util.ArrayList;
  18. import java.util.HashMap;
  19. import java.util.LinkedList;
  20. import java.util.List;
  21. import java.util.Map;
  22. import java.util.logging.Handler;
  23. import java.util.logging.Level;
  24. import java.util.logging.Logger;
  25. import com.google.gwt.core.client.EntryPoint;
  26. import com.google.gwt.core.client.GWT;
  27. import com.google.gwt.core.client.GWT.UncaughtExceptionHandler;
  28. import com.google.gwt.core.client.JavaScriptObject;
  29. import com.google.gwt.core.client.JsArrayString;
  30. import com.google.gwt.core.client.Scheduler;
  31. import com.google.gwt.core.client.Scheduler.ScheduledCommand;
  32. import com.google.gwt.logging.client.LogConfiguration;
  33. import com.google.gwt.user.client.Command;
  34. import com.google.gwt.user.client.Window;
  35. import com.vaadin.client.debug.internal.ErrorNotificationHandler;
  36. import com.vaadin.client.debug.internal.HierarchySection;
  37. import com.vaadin.client.debug.internal.InfoSection;
  38. import com.vaadin.client.debug.internal.LogSection;
  39. import com.vaadin.client.debug.internal.NetworkSection;
  40. import com.vaadin.client.debug.internal.ProfilerSection;
  41. import com.vaadin.client.debug.internal.Section;
  42. import com.vaadin.client.debug.internal.TestBenchSection;
  43. import com.vaadin.client.debug.internal.VDebugWindow;
  44. import com.vaadin.client.event.PointerEventSupport;
  45. import com.vaadin.client.metadata.BundleLoadCallback;
  46. import com.vaadin.client.metadata.ConnectorBundleLoader;
  47. import com.vaadin.client.metadata.NoDataException;
  48. import com.vaadin.client.metadata.TypeData;
  49. import com.vaadin.client.ui.UnknownComponentConnector;
  50. import com.vaadin.shared.ApplicationConstants;
  51. import com.vaadin.shared.ui.ui.UIConstants;
  52. public class ApplicationConfiguration implements EntryPoint {
  53. /**
  54. * Helper class for reading configuration options from the bootstap
  55. * javascript
  56. *
  57. * @since 7.0
  58. */
  59. private static class JsoConfiguration extends JavaScriptObject {
  60. protected JsoConfiguration() {
  61. // JSO Constructor
  62. }
  63. /**
  64. * Reads a configuration parameter as a string. Please note that the
  65. * javascript value of the parameter should also be a string, or else an
  66. * undefined exception may be thrown.
  67. *
  68. * @param name
  69. * name of the configuration parameter
  70. * @return value of the configuration parameter, or <code>null</code> if
  71. * not defined
  72. */
  73. private native String getConfigString(String name)
  74. /*-{
  75. var value = this.getConfig(name);
  76. if (value === null || value === undefined) {
  77. return null;
  78. } else {
  79. return value +"";
  80. }
  81. }-*/;
  82. /**
  83. * Reads a configuration parameter as a boolean object. Please note that
  84. * the javascript value of the parameter should also be a boolean, or
  85. * else an undefined exception may be thrown.
  86. *
  87. * @param name
  88. * name of the configuration parameter
  89. * @return boolean value of the configuration paramter, or
  90. * <code>null</code> if no value is defined
  91. */
  92. private native Boolean getConfigBoolean(String name)
  93. /*-{
  94. var value = this.getConfig(name);
  95. if (value === null || value === undefined) {
  96. return null;
  97. } else {
  98. // $entry not needed as function is not exported
  99. return @java.lang.Boolean::valueOf(Z)(value);
  100. }
  101. }-*/;
  102. /**
  103. * Reads a configuration parameter as an integer object. Please note
  104. * that the javascript value of the parameter should also be an integer,
  105. * or else an undefined exception may be thrown.
  106. *
  107. * @param name
  108. * name of the configuration parameter
  109. * @return integer value of the configuration paramter, or
  110. * <code>null</code> if no value is defined
  111. */
  112. private native Integer getConfigInteger(String name)
  113. /*-{
  114. var value = this.getConfig(name);
  115. if (value === null || value === undefined) {
  116. return null;
  117. } else {
  118. // $entry not needed as function is not exported
  119. return @java.lang.Integer::valueOf(I)(value);
  120. }
  121. }-*/;
  122. /**
  123. * Reads a configuration parameter as an {@link ErrorMessage} object.
  124. * Please note that the javascript value of the parameter should also be
  125. * an object with appropriate fields, or else an undefined exception may
  126. * be thrown when calling this method or when calling methods on the
  127. * returned object.
  128. *
  129. * @param name
  130. * name of the configuration parameter
  131. * @return error message with the given name, or <code>null</code> if no
  132. * value is defined
  133. */
  134. private native ErrorMessage getConfigError(String name)
  135. /*-{
  136. return this.getConfig(name);
  137. }-*/;
  138. /**
  139. * Returns a native javascript object containing version information
  140. * from the server.
  141. *
  142. * @return a javascript object with the version information
  143. */
  144. private native JavaScriptObject getVersionInfoJSObject()
  145. /*-{
  146. return this.getConfig("versionInfo");
  147. }-*/;
  148. /**
  149. * Gets the version of the Vaadin framework used on the server.
  150. *
  151. * @return a string with the version
  152. *
  153. * @see com.vaadin.server.VaadinServlet#VERSION
  154. */
  155. private native String getVaadinVersion()
  156. /*-{
  157. return this.getConfig("versionInfo").vaadinVersion;
  158. }-*/;
  159. private native String getUIDL()
  160. /*-{
  161. return this.getConfig("uidl");
  162. }-*/;
  163. }
  164. /**
  165. * Wraps a native javascript object containing fields for an error message
  166. *
  167. * @since 7.0
  168. */
  169. public static final class ErrorMessage extends JavaScriptObject {
  170. protected ErrorMessage() {
  171. // JSO constructor
  172. }
  173. public final native String getCaption()
  174. /*-{
  175. return this.caption;
  176. }-*/;
  177. public final native String getMessage()
  178. /*-{
  179. return this.message;
  180. }-*/;
  181. public final native String getUrl()
  182. /*-{
  183. return this.url;
  184. }-*/;
  185. }
  186. private static WidgetSet widgetSet = GWT.create(WidgetSet.class);
  187. private String id;
  188. /**
  189. * The URL to the VAADIN directory containing themes and widgetsets. Should
  190. * always end with a slash (/).
  191. */
  192. private String vaadinDirUrl;
  193. private String serviceUrl;
  194. private int uiId;
  195. private boolean standalone;
  196. private ErrorMessage communicationError;
  197. private ErrorMessage authorizationError;
  198. private ErrorMessage sessionExpiredError;
  199. private int heartbeatInterval;
  200. private HashMap<Integer, String> unknownComponents;
  201. private Map<Integer, Class<? extends ServerConnector>> classes = new HashMap<Integer, Class<? extends ServerConnector>>();
  202. private boolean browserDetailsSent = false;
  203. private boolean widgetsetVersionSent = false;
  204. static// TODO consider to make this hashmap per application
  205. LinkedList<Command> callbacks = new LinkedList<Command>();
  206. private static int dependenciesLoading;
  207. private static ArrayList<ApplicationConnection> runningApplications = new ArrayList<ApplicationConnection>();
  208. private Map<Integer, Integer> componentInheritanceMap = new HashMap<Integer, Integer>();
  209. private Map<Integer, String> tagToServerSideClassName = new HashMap<Integer, String>();
  210. /**
  211. * Checks whether path info in requests to the server-side service should be
  212. * in a request parameter (named <code>v-resourcePath</code>) or appended to
  213. * the end of the service URL.
  214. *
  215. * @see #getServiceUrl()
  216. *
  217. * @return <code>true</code> if path info should be a request parameter;
  218. * <code>false</code> if the path info goes after the service URL
  219. */
  220. public boolean useServiceUrlPathParam() {
  221. return getJsoConfiguration(id).getConfigBoolean(
  222. ApplicationConstants.SERVICE_URL_PATH_AS_PARAMETER) == Boolean.TRUE;
  223. }
  224. /**
  225. * Return the name of the parameter used to to send data to the service url.
  226. * This method should only be called if {@link #useServiceUrlPathParam()} is
  227. * true.
  228. *
  229. * @since 7.1.6
  230. * @return The parameter name, by default <code>v-resourcePath</code>
  231. */
  232. public String getServiceUrlParameterName() {
  233. String prefix = getJsoConfiguration(id).getConfigString(
  234. ApplicationConstants.SERVICE_URL_PARAMETER_NAMESPACE);
  235. if (prefix == null) {
  236. prefix = "";
  237. }
  238. return prefix + ApplicationConstants.V_RESOURCE_PATH;
  239. }
  240. public String getRootPanelId() {
  241. return id;
  242. }
  243. /**
  244. * Gets the URL to the server-side VaadinService. If
  245. * {@link #useServiceUrlPathParam()} return <code>true</code>, the requested
  246. * path info should be in the <code>v-resourcePath</code> query parameter;
  247. * else the path info should be appended to the end of the URL.
  248. *
  249. * @see #useServiceUrlPathParam()
  250. *
  251. * @return the URL to the server-side service as a string
  252. */
  253. public String getServiceUrl() {
  254. return serviceUrl;
  255. }
  256. public String getThemeName() {
  257. return getJsoConfiguration(id).getConfigString("theme");
  258. }
  259. public String getThemeUri() {
  260. return getVaadinDirUrl() + "themes/" + getThemeName();
  261. }
  262. /**
  263. * Gets the URL of the VAADIN directory on the server.
  264. *
  265. * @return the URL of the VAADIN directory
  266. */
  267. public String getVaadinDirUrl() {
  268. return vaadinDirUrl;
  269. }
  270. public void setAppId(String appId) {
  271. id = appId;
  272. }
  273. /**
  274. * Gets the initial UIDL from the DOM, if it was provided during the init
  275. * process.
  276. *
  277. * @return
  278. */
  279. public String getUIDL() {
  280. return getJsoConfiguration(id).getUIDL();
  281. }
  282. /**
  283. * @return true if the application is served by std. Vaadin servlet and is
  284. * considered to be the only or main content of the host page.
  285. */
  286. public boolean isStandalone() {
  287. return standalone;
  288. }
  289. /**
  290. * Gets the UI id of the server-side UI associated with this client-side
  291. * instance. The UI id should be included in every request originating from
  292. * this instance in order to associate the request with the right UI
  293. * instance on the server.
  294. *
  295. * @return the UI id
  296. */
  297. public int getUIId() {
  298. return uiId;
  299. }
  300. /**
  301. * @return The interval in seconds between heartbeat requests, or a
  302. * non-positive number if heartbeat is disabled.
  303. */
  304. public int getHeartbeatInterval() {
  305. return heartbeatInterval;
  306. }
  307. public JavaScriptObject getVersionInfoJSObject() {
  308. return getJsoConfiguration(id).getVersionInfoJSObject();
  309. }
  310. public ErrorMessage getCommunicationError() {
  311. return communicationError;
  312. }
  313. public ErrorMessage getAuthorizationError() {
  314. return authorizationError;
  315. }
  316. public ErrorMessage getSessionExpiredError() {
  317. return sessionExpiredError;
  318. }
  319. /**
  320. * Reads the configuration values defined by the bootstrap javascript.
  321. */
  322. private void loadFromDOM() {
  323. JsoConfiguration jsoConfiguration = getJsoConfiguration(id);
  324. serviceUrl = jsoConfiguration
  325. .getConfigString(ApplicationConstants.SERVICE_URL);
  326. if (serviceUrl == null || "".equals(serviceUrl)) {
  327. /*
  328. * Use the current url without query parameters and fragment as the
  329. * default value.
  330. */
  331. serviceUrl = Window.Location.getHref().replaceFirst("[?#].*", "");
  332. } else {
  333. /*
  334. * Resolve potentially relative URLs to ensure they point to the
  335. * desired locations even if the base URL of the page changes later
  336. * (e.g. with pushState)
  337. */
  338. serviceUrl = Util.getAbsoluteUrl(serviceUrl);
  339. }
  340. // Ensure there's an ending slash (to make appending e.g. UIDL work)
  341. if (!useServiceUrlPathParam() && !serviceUrl.endsWith("/")) {
  342. serviceUrl += '/';
  343. }
  344. vaadinDirUrl = Util.getAbsoluteUrl(jsoConfiguration
  345. .getConfigString(ApplicationConstants.VAADIN_DIR_URL));
  346. uiId = jsoConfiguration.getConfigInteger(UIConstants.UI_ID_PARAMETER)
  347. .intValue();
  348. // null -> false
  349. standalone = jsoConfiguration.getConfigBoolean("standalone") == Boolean.TRUE;
  350. heartbeatInterval = jsoConfiguration
  351. .getConfigInteger("heartbeatInterval");
  352. communicationError = jsoConfiguration.getConfigError("comErrMsg");
  353. authorizationError = jsoConfiguration.getConfigError("authErrMsg");
  354. sessionExpiredError = jsoConfiguration.getConfigError("sessExpMsg");
  355. // boostrap sets initPending to false if it has sent the browser details
  356. if (jsoConfiguration.getConfigBoolean("initPending") == Boolean.FALSE) {
  357. setBrowserDetailsSent();
  358. }
  359. }
  360. /**
  361. * Starts the application with a given id by reading the configuration
  362. * options stored by the bootstrap javascript.
  363. *
  364. * @param applicationId
  365. * id of the application to load, this is also the id of the html
  366. * element into which the application should be rendered.
  367. */
  368. public static void startApplication(final String applicationId) {
  369. Scheduler.get().scheduleDeferred(new ScheduledCommand() {
  370. @Override
  371. public void execute() {
  372. Profiler.enter("ApplicationConfiguration.startApplication");
  373. ApplicationConfiguration appConf = getConfigFromDOM(applicationId);
  374. ApplicationConnection a = GWT
  375. .create(ApplicationConnection.class);
  376. a.init(widgetSet, appConf);
  377. runningApplications.add(a);
  378. Profiler.leave("ApplicationConfiguration.startApplication");
  379. a.start();
  380. }
  381. });
  382. }
  383. public static List<ApplicationConnection> getRunningApplications() {
  384. return runningApplications;
  385. }
  386. /**
  387. * Gets the configuration object for a specific application from the
  388. * bootstrap javascript.
  389. *
  390. * @param appId
  391. * the id of the application to get configuration data for
  392. * @return a native javascript object containing the configuration data
  393. */
  394. private native static JsoConfiguration getJsoConfiguration(String appId)
  395. /*-{
  396. return $wnd.vaadin.getApp(appId);
  397. }-*/;
  398. public static ApplicationConfiguration getConfigFromDOM(String appId) {
  399. ApplicationConfiguration conf = new ApplicationConfiguration();
  400. conf.setAppId(appId);
  401. conf.loadFromDOM();
  402. return conf;
  403. }
  404. public String getServletVersion() {
  405. return getJsoConfiguration(id).getVaadinVersion();
  406. }
  407. public Class<? extends ServerConnector> getConnectorClassByEncodedTag(
  408. int tag) {
  409. Class<? extends ServerConnector> type = classes.get(tag);
  410. if (type == null && !classes.containsKey(tag)) {
  411. // Initialize if not already loaded
  412. Integer currentTag = Integer.valueOf(tag);
  413. while (type == null && currentTag != null) {
  414. String serverSideClassNameForTag = getServerSideClassNameForTag(currentTag);
  415. if (TypeData.hasIdentifier(serverSideClassNameForTag)) {
  416. try {
  417. type = (Class<? extends ServerConnector>) TypeData
  418. .getClass(serverSideClassNameForTag);
  419. } catch (NoDataException e) {
  420. throw new RuntimeException(e);
  421. }
  422. }
  423. currentTag = getParentTag(currentTag.intValue());
  424. }
  425. if (type == null) {
  426. type = UnknownComponentConnector.class;
  427. if (unknownComponents == null) {
  428. unknownComponents = new HashMap<Integer, String>();
  429. }
  430. unknownComponents.put(tag, getServerSideClassNameForTag(tag));
  431. }
  432. classes.put(tag, type);
  433. }
  434. return type;
  435. }
  436. public void addComponentInheritanceInfo(ValueMap valueMap) {
  437. JsArrayString keyArray = valueMap.getKeyArray();
  438. for (int i = 0; i < keyArray.length(); i++) {
  439. String key = keyArray.get(i);
  440. int value = valueMap.getInt(key);
  441. componentInheritanceMap.put(Integer.parseInt(key), value);
  442. }
  443. }
  444. public void addComponentMappings(ValueMap valueMap, WidgetSet widgetSet) {
  445. JsArrayString keyArray = valueMap.getKeyArray();
  446. for (int i = 0; i < keyArray.length(); i++) {
  447. String key = keyArray.get(i).intern();
  448. int value = valueMap.getInt(key);
  449. tagToServerSideClassName.put(value, key);
  450. }
  451. for (int i = 0; i < keyArray.length(); i++) {
  452. String key = keyArray.get(i).intern();
  453. int value = valueMap.getInt(key);
  454. widgetSet.ensureConnectorLoaded(value, this);
  455. }
  456. }
  457. /**
  458. * Returns all tags for given class. Tags are used in
  459. * {@link ApplicationConfiguration} to keep track of different classes and
  460. * their hierarchy
  461. *
  462. * @since 7.2
  463. * @param classname
  464. * name of class which tags we want
  465. * @return Integer array of tags pointing to this classname
  466. */
  467. public Integer[] getTagsForServerSideClassName(String classname) {
  468. List<Integer> tags = new ArrayList<Integer>();
  469. for (Map.Entry<Integer, String> entry : tagToServerSideClassName
  470. .entrySet()) {
  471. if (classname.equals(entry.getValue())) {
  472. tags.add(entry.getKey());
  473. }
  474. }
  475. Integer[] out = new Integer[tags.size()];
  476. return tags.toArray(out);
  477. }
  478. public Integer getParentTag(int tag) {
  479. return componentInheritanceMap.get(tag);
  480. }
  481. public String getServerSideClassNameForTag(Integer tag) {
  482. return tagToServerSideClassName.get(tag);
  483. }
  484. String getUnknownServerClassNameByTag(int tag) {
  485. if (unknownComponents != null) {
  486. return unknownComponents.get(tag);
  487. }
  488. return null;
  489. }
  490. /**
  491. *
  492. * @param c
  493. */
  494. static void runWhenDependenciesLoaded(Command c) {
  495. if (dependenciesLoading == 0) {
  496. c.execute();
  497. } else {
  498. callbacks.add(c);
  499. }
  500. }
  501. static void startDependencyLoading() {
  502. dependenciesLoading++;
  503. }
  504. static void endDependencyLoading() {
  505. dependenciesLoading--;
  506. if (dependenciesLoading == 0 && !callbacks.isEmpty()) {
  507. for (Command cmd : callbacks) {
  508. cmd.execute();
  509. }
  510. callbacks.clear();
  511. } else if (dependenciesLoading == 0
  512. && !ConnectorBundleLoader.get().isBundleLoaded(
  513. ConnectorBundleLoader.DEFERRED_BUNDLE_NAME)) {
  514. ConnectorBundleLoader.get().loadBundle(
  515. ConnectorBundleLoader.DEFERRED_BUNDLE_NAME,
  516. new BundleLoadCallback() {
  517. @Override
  518. public void loaded() {
  519. // Nothing to do
  520. }
  521. @Override
  522. public void failed(Throwable reason) {
  523. VConsole.error(reason);
  524. }
  525. });
  526. }
  527. }
  528. @Override
  529. public void onModuleLoad() {
  530. Profiler.initialize();
  531. Profiler.enter("ApplicationConfiguration.onModuleLoad");
  532. BrowserInfo browserInfo = BrowserInfo.get();
  533. // Enable iOS6 cast fix (see #10460)
  534. if (browserInfo.isIOS6() && browserInfo.isWebkit()) {
  535. enableIOS6castFix();
  536. }
  537. // Enable IE prompt fix (#13367)
  538. if (browserInfo.isIE() && browserInfo.getBrowserMajorVersion() >= 10) {
  539. enableIEPromptFix();
  540. }
  541. // Register pointer events (must be done before any events are used)
  542. PointerEventSupport.init();
  543. // Prepare the debugging window
  544. if (isDebugMode()) {
  545. /*
  546. * XXX Lots of implementation details here right now. This should be
  547. * cleared up when an API for extending the debug window is
  548. * implemented.
  549. */
  550. VDebugWindow window = GWT.create(VDebugWindow.class);
  551. if (LogConfiguration.loggingIsEnabled()) {
  552. window.addSection((Section) GWT.create(LogSection.class));
  553. }
  554. window.addSection((Section) GWT.create(InfoSection.class));
  555. window.addSection((Section) GWT.create(HierarchySection.class));
  556. window.addSection((Section) GWT.create(NetworkSection.class));
  557. window.addSection((Section) GWT.create(TestBenchSection.class));
  558. if (Profiler.isEnabled()) {
  559. window.addSection((Section) GWT.create(ProfilerSection.class));
  560. }
  561. if (isQuietDebugMode()) {
  562. window.close();
  563. } else {
  564. window.init();
  565. }
  566. // Connect to the legacy API
  567. VConsole.setImplementation(window);
  568. Handler errorNotificationHandler = GWT
  569. .create(ErrorNotificationHandler.class);
  570. Logger.getLogger("").addHandler(errorNotificationHandler);
  571. }
  572. if (LogConfiguration.loggingIsEnabled()) {
  573. GWT.setUncaughtExceptionHandler(new UncaughtExceptionHandler() {
  574. @Override
  575. public void onUncaughtException(Throwable e) {
  576. /*
  577. * If the debug window is not enabled (?debug), this will
  578. * not show anything to normal users. "a1 is not an object"
  579. * style errors helps nobody, especially end user. It does
  580. * not work tells just as much.
  581. */
  582. getLogger().log(Level.SEVERE, e.getMessage(), e);
  583. }
  584. });
  585. if (isProductionMode()) {
  586. // Disable all logging if in production mode
  587. Logger.getLogger("").setLevel(Level.OFF);
  588. }
  589. }
  590. Profiler.leave("ApplicationConfiguration.onModuleLoad");
  591. if (SuperDevMode.enableBasedOnParameter()) {
  592. // Do not start any application as super dev mode will refresh the
  593. // page once done compiling
  594. return;
  595. }
  596. registerCallback(GWT.getModuleName());
  597. }
  598. /**
  599. * Fix to iOS6 failing when comparing with 0 directly after the kind of
  600. * comparison done by GWT when a double or float is cast to an int. Forcing
  601. * another trivial operation (other than a compare to 0) after the dangerous
  602. * comparison makes the issue go away. See #10460.
  603. */
  604. private static native void enableIOS6castFix()
  605. /*-{
  606. Math.max = function(a,b) {return (a > b === 1 < 2)? a : b}
  607. Math.min = function(a,b) {return (a < b === 1 < 2)? a : b}
  608. }-*/;
  609. /**
  610. * Make Metro versions of IE suggest switching to the desktop when
  611. * window.prompt is called.
  612. */
  613. private static native void enableIEPromptFix()
  614. /*-{
  615. var prompt = $wnd.prompt;
  616. $wnd.prompt = function () {
  617. var result = prompt.apply($wnd, Array.prototype.slice.call(arguments));
  618. if (result === undefined) {
  619. // force the browser to suggest desktop mode
  620. showModalDialog();
  621. return null;
  622. } else {
  623. return result;
  624. }
  625. };
  626. }-*/;
  627. /**
  628. * Registers that callback that the bootstrap javascript uses to start
  629. * applications once the widgetset is loaded and all required information is
  630. * available
  631. *
  632. * @param widgetsetName
  633. * the name of this widgetset
  634. */
  635. public native static void registerCallback(String widgetsetName)
  636. /*-{
  637. var callbackHandler = $entry(@com.vaadin.client.ApplicationConfiguration::startApplication(Ljava/lang/String;));
  638. $wnd.vaadin.registerWidgetset(widgetsetName, callbackHandler);
  639. }-*/;
  640. /**
  641. * Checks if client side is in debug mode. Practically this is invoked by
  642. * adding ?debug parameter to URI. Please note that debug mode is always
  643. * disabled if production mode is enabled, but disabling production mode
  644. * does not automatically enable debug mode.
  645. *
  646. * @see #isProductionMode()
  647. *
  648. * @return true if client side is currently been debugged
  649. */
  650. public static boolean isDebugMode() {
  651. return isDebugAvailable()
  652. && Window.Location.getParameter("debug") != null;
  653. }
  654. /**
  655. * Checks if production mode is enabled. When production mode is enabled,
  656. * client-side logging is disabled. There may also be other performance
  657. * optimizations.
  658. *
  659. * @since 7.1.2
  660. * @return <code>true</code> if production mode is enabled; otherwise
  661. * <code>false</code>.
  662. */
  663. public static boolean isProductionMode() {
  664. return !isDebugAvailable();
  665. }
  666. private native static boolean isDebugAvailable()
  667. /*-{
  668. if($wnd.vaadin.debug) {
  669. return true;
  670. } else {
  671. return false;
  672. }
  673. }-*/;
  674. /**
  675. * Checks whether debug logging should be quiet
  676. *
  677. * @return <code>true</code> if debug logging should be quiet
  678. */
  679. public static boolean isQuietDebugMode() {
  680. String debugParameter = Window.Location.getParameter("debug");
  681. return isDebugAvailable() && debugParameter != null
  682. && debugParameter.startsWith("q");
  683. }
  684. /**
  685. * Checks whether information from the web browser (e.g. uri fragment and
  686. * screen size) has been sent to the server.
  687. *
  688. * @return <code>true</code> if browser information has already been sent
  689. *
  690. * @see ApplicationConnection#getNativeBrowserDetailsParameters(String)
  691. */
  692. public boolean isBrowserDetailsSent() {
  693. return browserDetailsSent;
  694. }
  695. /**
  696. * Registers that the browser details have been sent.
  697. * {@link #isBrowserDetailsSent()} will return
  698. * <code> after this method has been invoked.
  699. */
  700. public void setBrowserDetailsSent() {
  701. browserDetailsSent = true;
  702. }
  703. /**
  704. * Checks whether the widget set version has been sent to the server. It is
  705. * sent in the first UIDL request.
  706. *
  707. * @return <code>true</code> if browser information has already been sent
  708. *
  709. * @see ApplicationConnection#getNativeBrowserDetailsParameters(String)
  710. */
  711. public boolean isWidgetsetVersionSent() {
  712. return widgetsetVersionSent;
  713. }
  714. /**
  715. * Registers that the widget set version has been sent to the server.
  716. */
  717. public void setWidgetsetVersionSent() {
  718. widgetsetVersionSent = true;
  719. }
  720. private static final Logger getLogger() {
  721. return Logger.getLogger(ApplicationConfiguration.class.getName());
  722. }
  723. }