Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(409)

Side by Side Diff: chrome/browser/resources/uber/uber.js

Issue 418663002: Typecheck JS files for chrome://help before doing import transition (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@json_to_pydict
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/resources/uber/uber_utils.js » ('j') | compiled_resources.py » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 cr.define('uber', function() { 5 cr.define('uber', function() {
6 /** 6 /**
7 * Options for how web history should be handled. 7 * Options for how web history should be handled.
8 */ 8 */
9 var HISTORY_STATE_OPTION = { 9 var HISTORY_STATE_OPTION = {
10 PUSH: 1, // Push a new history state. 10 PUSH: 1, // Push a new history state.
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 * { method : "methodToInvoke", 142 * { method : "methodToInvoke",
143 * params : {...} 143 * params : {...}
144 * } 144 * }
145 * 145 *
146 * |method| is required, while |params| is optional. Extra parameters required 146 * |method| is required, while |params| is optional. Extra parameters required
147 * by a method must be specified by that method's documentation. 147 * by a method must be specified by that method's documentation.
148 * 148 *
149 * @param {Event} e The posted object. 149 * @param {Event} e The posted object.
150 */ 150 */
151 function handleWindowMessage(e) { 151 function handleWindowMessage(e) {
152 e = /** @type{!MessageEvent.<!{method: string, params: *}>} */ (e);
Dan Beam 2014/07/23 22:09:24 we should stay consistent regarding /** @type {
Vitaly Pavlenko 2014/07/24 01:09:31 Done.
152 if (e.data.method === 'beginInterceptingEvents') { 153 if (e.data.method === 'beginInterceptingEvents') {
153 backgroundNavigation(); 154 backgroundNavigation();
154 } else if (e.data.method === 'stopInterceptingEvents') { 155 } else if (e.data.method === 'stopInterceptingEvents') {
155 foregroundNavigation(); 156 foregroundNavigation();
156 } else if (e.data.method === 'ready') { 157 } else if (e.data.method === 'ready') {
157 pageReady(e.origin); 158 pageReady(e.origin);
158 } else if (e.data.method === 'updateHistory') { 159 } else if (e.data.method === 'updateHistory') {
159 updateHistory(e.origin, e.data.params.state, e.data.params.path, 160 updateHistory(e.origin, e.data.params.state, e.data.params.path,
160 e.data.params.replace); 161 e.data.params.replace);
161 } else if (e.data.method === 'setTitle') { 162 } else if (e.data.method === 'setTitle') {
162 setTitle(e.origin, e.data.params.title); 163 setTitle(e.origin, e.data.params.title);
163 } else if (e.data.method === 'showPage') { 164 } else if (e.data.method === 'showPage') {
164 showPage(e.data.params.pageId, 165 showPage(e.data.params.pageId,
165 HISTORY_STATE_OPTION.PUSH, 166 HISTORY_STATE_OPTION.PUSH,
166 e.data.params.path); 167 e.data.params.path);
167 } else if (e.data.method === 'navigationControlsLoaded') { 168 } else if (e.data.method === 'navigationControlsLoaded') {
168 onNavigationControlsLoaded(); 169 onNavigationControlsLoaded();
169 } else if (e.data.method === 'adjustToScroll') { 170 } else if (e.data.method === 'adjustToScroll') {
170 adjustToScroll(e.data.params); 171 adjustToScroll(/** @type {number} */(e.data.params));
171 } else if (e.data.method === 'mouseWheel') { 172 } else if (e.data.method === 'mouseWheel') {
172 forwardMouseWheel(e.data.params); 173 forwardMouseWheel(/** @type {Object} */(e.data.params));
173 } else { 174 } else {
174 console.error('Received unexpected message', e.data); 175 console.error('Received unexpected message', e.data);
175 } 176 }
176 } 177 }
177 178
178 /** 179 /**
179 * Sends the navigation iframe to the background. 180 * Sends the navigation iframe to the background.
180 */ 181 */
181 function backgroundNavigation() { 182 function backgroundNavigation() {
182 navFrame.classList.add('background'); 183 navFrame.classList.add('background');
(...skipping 21 matching lines...) Expand all
204 if (isRTL()) { 205 if (isRTL()) {
205 uber.invokeMethodOnWindow(navFrame.firstChild.contentWindow, 206 uber.invokeMethodOnWindow(navFrame.firstChild.contentWindow,
206 'setContentChanging', 207 'setContentChanging',
207 enabled); 208 enabled);
208 } 209 }
209 } 210 }
210 211
211 /** 212 /**
212 * Get an iframe based on the origin of a received post message. 213 * Get an iframe based on the origin of a received post message.
213 * @param {string} origin The origin of a post message. 214 * @param {string} origin The origin of a post message.
214 * @return {!HTMLElement} The frame associated to |origin| or null. 215 * @return {!Element} The frame associated to |origin| or null.
215 */ 216 */
216 function getIframeFromOrigin(origin) { 217 function getIframeFromOrigin(origin) {
217 assert(origin.substr(-1) != '/', 'invalid origin given'); 218 assert(origin.substr(-1) != '/', 'invalid origin given');
218 var query = '.iframe-container > iframe[src^="' + origin + '/"]'; 219 var query = '.iframe-container > iframe[src^="' + origin + '/"]';
219 return document.querySelector(query); 220 var element = document.querySelector(query);
221 assert(element, 'expected an element');
222 return /** @type {!Element} */ (element);
220 } 223 }
221 224
222 /** 225 /**
223 * Changes the path past the page title (i.e. chrome://chrome/settings/(.*)). 226 * Changes the path past the page title (i.e. chrome://chrome/settings/(.*)).
224 * @param {Object} state The page's state object for the navigation. 227 * @param {Object} state The page's state object for the navigation.
225 * @param {string} path The new /path/ to be set after the page name. 228 * @param {string} path The new /path/ to be set after the page name.
226 * @param {number} historyOption The type of history modification to make. 229 * @param {number} historyOption The type of history modification to make.
227 */ 230 */
228 function changePathTo(state, path, historyOption) { 231 function changePathTo(state, path, historyOption) {
229 assert(!path || path.substr(-1) != '/', 'invalid path given'); 232 assert(!path || path.substr(-1) != '/', 'invalid path given');
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 var queue = queuedInvokes[container.id] || []; 309 var queue = queuedInvokes[container.id] || [];
307 queuedInvokes[container.id] = undefined; 310 queuedInvokes[container.id] = undefined;
308 for (var i = 0; i < queue.length; i++) { 311 for (var i = 0; i < queue.length; i++) {
309 uber.invokeMethodOnWindow(frame.contentWindow, queue[i][0], queue[i][1]); 312 uber.invokeMethodOnWindow(frame.contentWindow, queue[i][0], queue[i][1]);
310 } 313 }
311 } 314 }
312 315
313 /** 316 /**
314 * Selects and navigates a subpage. This is called from uber-frame. 317 * Selects and navigates a subpage. This is called from uber-frame.
315 * @param {string} pageId Should match an id of one of the iframe containers. 318 * @param {string} pageId Should match an id of one of the iframe containers.
316 * @param {integer} historyOption Indicates whether we should push or replace 319 * @param {number} historyOption Indicates whether we should push or replace
317 * browser history. 320 * browser history.
318 * @param {string} path A sub-page path. 321 * @param {string} path A sub-page path.
319 */ 322 */
320 function showPage(pageId, historyOption, path) { 323 function showPage(pageId, historyOption, path) {
321 var container = $(pageId); 324 var container = $(pageId);
322 325
323 // Lazy load of iframe contents. 326 // Lazy load of iframe contents.
324 var sourceUrl = container.dataset.url + (path || ''); 327 var sourceUrl = container.dataset.url + (path || '');
325 var frame = container.querySelector('iframe'); 328 var frame = container.querySelector('iframe');
326 if (!frame) { 329 if (!frame) {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 adjustToScroll(0); 367 adjustToScroll(0);
365 368
366 var selectedFrame = getSelectedIframe().querySelector('iframe'); 369 var selectedFrame = getSelectedIframe().querySelector('iframe');
367 uber.invokeMethodOnWindow(selectedFrame.contentWindow, 'frameSelected'); 370 uber.invokeMethodOnWindow(selectedFrame.contentWindow, 'frameSelected');
368 371
369 if (historyOption != HISTORY_STATE_OPTION.NONE) 372 if (historyOption != HISTORY_STATE_OPTION.NONE)
370 changePathTo({}, path, historyOption); 373 changePathTo({}, path, historyOption);
371 374
372 if (container.dataset.title) 375 if (container.dataset.title)
373 document.title = container.dataset.title; 376 document.title = container.dataset.title;
374 $('favicon').href = 'chrome://theme/' + container.dataset.favicon; 377 assert('favicon' in container.dataset);
375 $('favicon2x').href = 'chrome://theme/' + container.dataset.favicon + '@2x'; 378
379 var dataset = /** @type {{favicon: string}} */ (container.dataset);
380 $('favicon').href = 'chrome://theme/' + dataset.favicon;
381 $('favicon2x').href = 'chrome://theme/' + dataset.favicon + '@2x';
376 382
377 updateNavigationControls(); 383 updateNavigationControls();
378 } 384 }
379 385
380 function onNavigationControlsLoaded() { 386 function onNavigationControlsLoaded() {
381 updateNavigationControls(); 387 updateNavigationControls();
382 } 388 }
383 389
384 /** 390 /**
385 * Sends a message to uber-frame to update the appearance of the nav controls. 391 * Sends a message to uber-frame to update the appearance of the nav controls.
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 } 452 }
447 453
448 return { 454 return {
449 onLoad: onLoad, 455 onLoad: onLoad,
450 onPopHistoryState: onPopHistoryState 456 onPopHistoryState: onPopHistoryState
451 }; 457 };
452 }); 458 });
453 459
454 window.addEventListener('popstate', uber.onPopHistoryState); 460 window.addEventListener('popstate', uber.onPopHistoryState);
455 document.addEventListener('DOMContentLoaded', uber.onLoad); 461 document.addEventListener('DOMContentLoaded', uber.onLoad);
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/resources/uber/uber_utils.js » ('j') | compiled_resources.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698