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

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