Commit 97af9a26 authored by vitalyp@chromium.org's avatar vitalyp@chromium.org

Typecheck JS files for chrome://help before doing import transition

BUG=393873
R=dbeam@chromium.org

Review URL: https://codereview.chromium.org/418663002

Cr-Commit-Position: refs/heads/master@{#288504}
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@288504 0039d316-1c4b-4281-b951-d872f2087c98
parent 38fb28f9
...@@ -149,6 +149,7 @@ cr.define('uber', function() { ...@@ -149,6 +149,7 @@ cr.define('uber', function() {
* @param {Event} e The posted object. * @param {Event} e The posted object.
*/ */
function handleWindowMessage(e) { function handleWindowMessage(e) {
e = /** @type{!MessageEvent.<!{method: string, params: *}>} */(e);
if (e.data.method === 'beginInterceptingEvents') { if (e.data.method === 'beginInterceptingEvents') {
backgroundNavigation(); backgroundNavigation();
} else if (e.data.method === 'stopInterceptingEvents') { } else if (e.data.method === 'stopInterceptingEvents') {
...@@ -167,9 +168,9 @@ cr.define('uber', function() { ...@@ -167,9 +168,9 @@ cr.define('uber', function() {
} else if (e.data.method === 'navigationControlsLoaded') { } else if (e.data.method === 'navigationControlsLoaded') {
onNavigationControlsLoaded(); onNavigationControlsLoaded();
} else if (e.data.method === 'adjustToScroll') { } else if (e.data.method === 'adjustToScroll') {
adjustToScroll(e.data.params); adjustToScroll(/** @type {number} */(e.data.params));
} else if (e.data.method === 'mouseWheel') { } else if (e.data.method === 'mouseWheel') {
forwardMouseWheel(e.data.params); forwardMouseWheel(/** @type {Object} */(e.data.params));
} else { } else {
console.error('Received unexpected message', e.data); console.error('Received unexpected message', e.data);
} }
...@@ -203,20 +204,21 @@ cr.define('uber', function() { ...@@ -203,20 +204,21 @@ cr.define('uber', function() {
if (isRTL()) { if (isRTL()) {
uber.invokeMethodOnWindow(navFrame.firstChild.contentWindow, uber.invokeMethodOnWindow(navFrame.firstChild.contentWindow,
'setContentChanging', 'setContentChanging', enabled);
enabled);
} }
} }
/** /**
* Get an iframe based on the origin of a received post message. * Get an iframe based on the origin of a received post message.
* @param {string} origin The origin of a post message. * @param {string} origin The origin of a post message.
* @return {!HTMLElement} The frame associated to |origin| or null. * @return {!Element} The frame associated to |origin| or null.
*/ */
function getIframeFromOrigin(origin) { function getIframeFromOrigin(origin) {
assert(origin.substr(-1) != '/', 'invalid origin given'); assert(origin.substr(-1) != '/', 'invalid origin given');
var query = '.iframe-container > iframe[src^="' + origin + '/"]'; var query = '.iframe-container > iframe[src^="' + origin + '/"]';
return document.querySelector(query); var element = document.querySelector(query);
assert(element);
return /** @type {!Element} */(element);
} }
/** /**
...@@ -313,7 +315,7 @@ cr.define('uber', function() { ...@@ -313,7 +315,7 @@ cr.define('uber', function() {
/** /**
* Selects and navigates a subpage. This is called from uber-frame. * Selects and navigates a subpage. This is called from uber-frame.
* @param {string} pageId Should match an id of one of the iframe containers. * @param {string} pageId Should match an id of one of the iframe containers.
* @param {integer} historyOption Indicates whether we should push or replace * @param {number} historyOption Indicates whether we should push or replace
* browser history. * browser history.
* @param {string} path A sub-page path. * @param {string} path A sub-page path.
*/ */
...@@ -371,8 +373,11 @@ cr.define('uber', function() { ...@@ -371,8 +373,11 @@ cr.define('uber', function() {
if (container.dataset.title) if (container.dataset.title)
document.title = container.dataset.title; document.title = container.dataset.title;
$('favicon').href = 'chrome://theme/' + container.dataset.favicon; assert('favicon' in container.dataset);
$('favicon2x').href = 'chrome://theme/' + container.dataset.favicon + '@2x';
var dataset = /** @type {{favicon: string}} */(container.dataset);
$('favicon').href = 'chrome://theme/' + dataset.favicon;
$('favicon2x').href = 'chrome://theme/' + dataset.favicon + '@2x';
updateNavigationControls(); updateNavigationControls();
} }
......
...@@ -51,17 +51,19 @@ cr.define('uber', function() { ...@@ -51,17 +51,19 @@ cr.define('uber', function() {
} }
invokeMethodOnParent('adjustToScroll', scrollLeft); invokeMethodOnParent('adjustToScroll', scrollLeft);
}; }
/** /**
* Handles 'message' events on window. * Handles 'message' events on window.
* @param {Event} e The message event. * @param {Event} e The message event.
*/ */
function handleWindowMessage(e) { function handleWindowMessage(e) {
e = /** @type {!MessageEvent.<!{method: string, params: *}>} */(e);
if (e.data.method === 'frameSelected') if (e.data.method === 'frameSelected')
handleFrameSelected(); handleFrameSelected();
else if (e.data.method === 'mouseWheel') else if (e.data.method === 'mouseWheel')
handleMouseWheel(e.data.params); handleMouseWheel(
/** @type {{deltaX: number, deltaY: number}} */(e.data.params));
else if (e.data.method === 'popState') else if (e.data.method === 'popState')
handlePopState(e.data.params.state, e.data.params.path); handlePopState(e.data.params.state, e.data.params.path);
} }
...@@ -82,7 +84,8 @@ cr.define('uber', function() { ...@@ -82,7 +84,8 @@ cr.define('uber', function() {
* It differs for every platform and even initWebKitWheelEvent takes a * It differs for every platform and even initWebKitWheelEvent takes a
* pixel amount instead of a wheel delta. So we just choose something * pixel amount instead of a wheel delta. So we just choose something
* reasonable and hope no one notices the difference. * reasonable and hope no one notices the difference.
* @param {Object} params A structure that holds wheel deltas in X and Y. * @param {{deltaX: number, deltaY: number}} params A structure that holds
* wheel deltas in X and Y.
*/ */
function handleMouseWheel(params) { function handleMouseWheel(params) {
window.scrollBy(-params.deltaX * 49 / 120, -params.deltaY * 49 / 120); window.scrollBy(-params.deltaX * 49 / 120, -params.deltaY * 49 / 120);
...@@ -91,9 +94,12 @@ cr.define('uber', function() { ...@@ -91,9 +94,12 @@ cr.define('uber', function() {
/** /**
* Called when the parent window restores some state saved by uber.pushState * Called when the parent window restores some state saved by uber.pushState
* or uber.replaceState. Simulates a popstate event. * or uber.replaceState. Simulates a popstate event.
* @param {PopStateEvent} state A state object for replaceState and pushState.
* @param {string} path The path the page navigated to.
* @suppress {checkTypes}
*/ */
function handlePopState(state, path) { function handlePopState(state, path) {
history.replaceState(state, '', path); window.history.replaceState(state, '', path);
window.dispatchEvent(new PopStateEvent('popstate', {state: state})); window.dispatchEvent(new PopStateEvent('popstate', {state: state}));
} }
...@@ -108,8 +114,8 @@ cr.define('uber', function() { ...@@ -108,8 +114,8 @@ cr.define('uber', function() {
* Invokes a method on the parent window (UberPage). This is a convenience * Invokes a method on the parent window (UberPage). This is a convenience
* method for API calls into the uber page. * method for API calls into the uber page.
* @param {string} method The name of the method to invoke. * @param {string} method The name of the method to invoke.
* @param {Object=} opt_params Optional property bag of parameters to pass to * @param {(Object|number)=} opt_params Optional property bag of parameters
* the invoked method. * to pass to the invoked method.
* @private * @private
*/ */
function invokeMethodOnParent(method, opt_params) { function invokeMethodOnParent(method, opt_params) {
...@@ -122,8 +128,8 @@ cr.define('uber', function() { ...@@ -122,8 +128,8 @@ cr.define('uber', function() {
/** /**
* Invokes a method on the target window. * Invokes a method on the target window.
* @param {string} method The name of the method to invoke. * @param {string} method The name of the method to invoke.
* @param {Object=} opt_params Optional property bag of parameters to pass to * @param {(Object|number)=} opt_params Optional property bag of parameters
* the invoked method. * to pass to the invoked method.
* @param {string=} opt_url The origin of the target window. * @param {string=} opt_url The origin of the target window.
* @private * @private
*/ */
...@@ -137,7 +143,6 @@ cr.define('uber', function() { ...@@ -137,7 +143,6 @@ cr.define('uber', function() {
* forward the information to the parent for it to manage history for us. This * forward the information to the parent for it to manage history for us. This
* is a replacement of history.replaceState and history.pushState. * is a replacement of history.replaceState and history.pushState.
* @param {Object} state A state object for replaceState and pushState. * @param {Object} state A state object for replaceState and pushState.
* @param {string} title The title of the page to replace.
* @param {string} path The path the page navigated to. * @param {string} path The path the page navigated to.
* @param {boolean} replace If true, navigate with replacement. * @param {boolean} replace If true, navigate with replacement.
* @private * @private
......
...@@ -23,13 +23,13 @@ cr.define('cr.ui', function() { ...@@ -23,13 +23,13 @@ cr.define('cr.ui', function() {
/** /**
* Determines whether the |child| is a descendant of |parent| in the page's * Determines whether the |child| is a descendant of |parent| in the page's
* DOM. * DOM.
* @param {Element} parent The parent element to test. * @param {Node} parent The parent element to test.
* @param {Element} child The child element to test. * @param {Node} child The child element to test.
* @return {boolean} True if |child| is a descendant of |parent|. * @return {boolean} True if |child| is a descendant of |parent|.
* @private * @private
*/ */
isDescendantOf_: function(parent, child) { isDescendantOf_: function(parent, child) {
return parent && !(parent === child) && parent.contains(child); return !!parent && !(parent === child) && parent.contains(child);
}, },
/** /**
...@@ -43,7 +43,7 @@ cr.define('cr.ui', function() { ...@@ -43,7 +43,7 @@ cr.define('cr.ui', function() {
/** /**
* Returns the elements on the page capable of receiving focus. * Returns the elements on the page capable of receiving focus.
* @return {Array.Element} The focusable elements. * @return {Array.<Element>} The focusable elements.
*/ */
getFocusableElements_: function() { getFocusableElements_: function() {
var focusableDiv = this.getFocusParent(); var focusableDiv = this.getFocusParent();
...@@ -52,7 +52,9 @@ cr.define('cr.ui', function() { ...@@ -52,7 +52,9 @@ cr.define('cr.ui', function() {
var treeWalker = document.createTreeWalker( var treeWalker = document.createTreeWalker(
focusableDiv, focusableDiv,
NodeFilter.SHOW_ELEMENT, NodeFilter.SHOW_ELEMENT,
{ acceptNode: function(node) { /** @type {NodeFilter} */
({
acceptNode: function(node) {
var style = window.getComputedStyle(node); var style = window.getComputedStyle(node);
// Reject all hidden nodes. FILTER_REJECT also rejects these // Reject all hidden nodes. FILTER_REJECT also rejects these
// nodes' children, so non-hidden elements that are descendants of // nodes' children, so non-hidden elements that are descendants of
...@@ -70,7 +72,7 @@ cr.define('cr.ui', function() { ...@@ -70,7 +72,7 @@ cr.define('cr.ui', function() {
// Accept nodes that are non-hidden and focusable. // Accept nodes that are non-hidden and focusable.
return NodeFilter.FILTER_ACCEPT; return NodeFilter.FILTER_ACCEPT;
} }
}, }),
false); false);
var focusable = []; var focusable = [];
...@@ -87,7 +89,7 @@ cr.define('cr.ui', function() { ...@@ -87,7 +89,7 @@ cr.define('cr.ui', function() {
* event. This differs from the native 'focus' event which is received by * event. This differs from the native 'focus' event which is received by
* an element outside the page first, followed by a 'focus' on an element * an element outside the page first, followed by a 'focus' on an element
* within the page after the FocusManager has intervened. * within the page after the FocusManager has intervened.
* @param {Element} element The element that has received focus. * @param {EventTarget} element The element that has received focus.
* @private * @private
*/ */
dispatchFocusEvent_: function(element) { dispatchFocusEvent_: function(element) {
...@@ -148,7 +150,8 @@ cr.define('cr.ui', function() { ...@@ -148,7 +150,8 @@ cr.define('cr.ui', function() {
onDocumentFocus_: function(event) { onDocumentFocus_: function(event) {
// If the element being focused is a descendant of the currently visible // If the element being focused is a descendant of the currently visible
// page, focus is valid. // page, focus is valid.
if (this.isDescendantOf_(this.getFocusParent(), event.target)) { var targetNode = /** @type {Node} */(event.target);
if (this.isDescendantOf_(this.getFocusParent(), targetNode)) {
this.dispatchFocusEvent_(event.target); this.dispatchFocusEvent_(event.target);
return; return;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment