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 26KB

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