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() {
* @param {Event} e The posted object.
*/
function handleWindowMessage(e) {
e = /** @type{!MessageEvent.<!{method: string, params: *}>} */(e);
if (e.data.method === 'beginInterceptingEvents') {
backgroundNavigation();
} else if (e.data.method === 'stopInterceptingEvents') {
......@@ -167,9 +168,9 @@ cr.define('uber', function() {
} else if (e.data.method === 'navigationControlsLoaded') {
onNavigationControlsLoaded();
} else if (e.data.method === 'adjustToScroll') {
adjustToScroll(e.data.params);
adjustToScroll(/** @type {number} */(e.data.params));
} else if (e.data.method === 'mouseWheel') {
forwardMouseWheel(e.data.params);
forwardMouseWheel(/** @type {Object} */(e.data.params));
} else {
console.error('Received unexpected message', e.data);
}
......@@ -203,20 +204,21 @@ cr.define('uber', function() {
if (isRTL()) {
uber.invokeMethodOnWindow(navFrame.firstChild.contentWindow,
'setContentChanging',
enabled);
'setContentChanging', enabled);
}
}
/**
* Get an iframe based on the origin of a received 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) {
assert(origin.substr(-1) != '/', 'invalid origin given');
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() {
/**
* 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 {integer} historyOption Indicates whether we should push or replace
* @param {number} historyOption Indicates whether we should push or replace
* browser history.
* @param {string} path A sub-page path.
*/
......@@ -371,8 +373,11 @@ cr.define('uber', function() {
if (container.dataset.title)
document.title = container.dataset.title;
$('favicon').href = 'chrome://theme/' + container.dataset.favicon;
$('favicon2x').href = 'chrome://theme/' + container.dataset.favicon + '@2x';
assert('favicon' in container.dataset);
var dataset = /** @type {{favicon: string}} */(container.dataset);
$('favicon').href = 'chrome://theme/' + dataset.favicon;
$('favicon2x').href = 'chrome://theme/' + dataset.favicon + '@2x';
updateNavigationControls();
}
......
......@@ -51,17 +51,19 @@ cr.define('uber', function() {
}
invokeMethodOnParent('adjustToScroll', scrollLeft);
};
}
/**
* Handles 'message' events on window.
* @param {Event} e The message event.
*/
function handleWindowMessage(e) {
e = /** @type {!MessageEvent.<!{method: string, params: *}>} */(e);
if (e.data.method === 'frameSelected')
handleFrameSelected();
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')
handlePopState(e.data.params.state, e.data.params.path);
}
......@@ -82,7 +84,8 @@ cr.define('uber', function() {
* It differs for every platform and even initWebKitWheelEvent takes a
* pixel amount instead of a wheel delta. So we just choose something
* 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) {
window.scrollBy(-params.deltaX * 49 / 120, -params.deltaY * 49 / 120);
......@@ -91,9 +94,12 @@ cr.define('uber', function() {
/**
* Called when the parent window restores some state saved by uber.pushState
* 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) {
history.replaceState(state, '', path);
window.history.replaceState(state, '', path);
window.dispatchEvent(new PopStateEvent('popstate', {state: state}));
}
......@@ -108,8 +114,8 @@ cr.define('uber', function() {
* Invokes a method on the parent window (UberPage). This is a convenience
* method for API calls into the uber page.
* @param {string} method The name of the method to invoke.
* @param {Object=} opt_params Optional property bag of parameters to pass to
* the invoked method.
* @param {(Object|number)=} opt_params Optional property bag of parameters
* to pass to the invoked method.
* @private
*/
function invokeMethodOnParent(method, opt_params) {
......@@ -122,8 +128,8 @@ cr.define('uber', function() {
/**
* Invokes a method on the target window.
* @param {string} method The name of the method to invoke.
* @param {Object=} opt_params Optional property bag of parameters to pass to
* the invoked method.
* @param {(Object|number)=} opt_params Optional property bag of parameters
* to pass to the invoked method.
* @param {string=} opt_url The origin of the target window.
* @private
*/
......@@ -137,7 +143,6 @@ cr.define('uber', function() {
* forward the information to the parent for it to manage history for us. This
* is a replacement of history.replaceState and history.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 {boolean} replace If true, navigate with replacement.
* @private
......
......@@ -23,13 +23,13 @@ cr.define('cr.ui', function() {
/**
* Determines whether the |child| is a descendant of |parent| in the page's
* DOM.
* @param {Element} parent The parent element to test.
* @param {Element} child The child element to test.
* @param {Node} parent The parent element to test.
* @param {Node} child The child element to test.
* @return {boolean} True if |child| is a descendant of |parent|.
* @private
*/
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() {
/**
* Returns the elements on the page capable of receiving focus.
* @return {Array.Element} The focusable elements.
* @return {Array.<Element>} The focusable elements.
*/
getFocusableElements_: function() {
var focusableDiv = this.getFocusParent();
......@@ -52,7 +52,9 @@ cr.define('cr.ui', function() {
var treeWalker = document.createTreeWalker(
focusableDiv,
NodeFilter.SHOW_ELEMENT,
{ acceptNode: function(node) {
/** @type {NodeFilter} */
({
acceptNode: function(node) {
var style = window.getComputedStyle(node);
// Reject all hidden nodes. FILTER_REJECT also rejects these
// nodes' children, so non-hidden elements that are descendants of
......@@ -70,7 +72,7 @@ cr.define('cr.ui', function() {
// Accept nodes that are non-hidden and focusable.
return NodeFilter.FILTER_ACCEPT;
}
},
}),
false);
var focusable = [];
......@@ -87,7 +89,7 @@ cr.define('cr.ui', function() {
* 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
* 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
*/
dispatchFocusEvent_: function(element) {
......@@ -148,7 +150,8 @@ cr.define('cr.ui', function() {
onDocumentFocus_: function(event) {
// If the element being focused is a descendant of the currently visible
// 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);
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