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

Side by Side Diff: chrome/common/extensions/docs/examples/api/webNavigation/basic/navigation_collector.js

Issue 10704225: Send an webNavigation event for navigations triggered by window.history (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 /** 5 /**
6 * Implements the NavigationCollector object that powers the extension. 6 * Implements the NavigationCollector object that powers the extension.
7 * 7 *
8 * @author mkwst@google.com (Mike West) 8 * @author mkwst@google.com (Mike West)
9 */ 9 */
10 10
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 chrome.webNavigation.onBeforeNavigate.addListener( 53 chrome.webNavigation.onBeforeNavigate.addListener(
54 this.onBeforeNavigateListener_.bind(this)); 54 this.onBeforeNavigateListener_.bind(this));
55 chrome.webNavigation.onCompleted.addListener( 55 chrome.webNavigation.onCompleted.addListener(
56 this.onCompletedListener_.bind(this)); 56 this.onCompletedListener_.bind(this));
57 chrome.webNavigation.onCommitted.addListener( 57 chrome.webNavigation.onCommitted.addListener(
58 this.onCommittedListener_.bind(this)); 58 this.onCommittedListener_.bind(this));
59 chrome.webNavigation.onErrorOccurred.addListener( 59 chrome.webNavigation.onErrorOccurred.addListener(
60 this.onErrorOccurredListener_.bind(this)); 60 this.onErrorOccurredListener_.bind(this));
61 chrome.webNavigation.onReferenceFragmentUpdated.addListener( 61 chrome.webNavigation.onReferenceFragmentUpdated.addListener(
62 this.onReferenceFragmentUpdatedListener_.bind(this)); 62 this.onReferenceFragmentUpdatedListener_.bind(this));
63 chrome.webNavigation.onHistoryStateUpdated.addListener(
64 this.onHistoryStateUpdatedListener_.bind(this));
63 65
64 // Bind handler to extension messages for communication from popup. 66 // Bind handler to extension messages for communication from popup.
65 chrome.extension.onRequest.addListener(this.onRequestListener_.bind(this)); 67 chrome.extension.onRequest.addListener(this.onRequestListener_.bind(this));
66 } 68 }
67 69
68 /////////////////////////////////////////////////////////////////////////////// 70 ///////////////////////////////////////////////////////////////////////////////
69 71
70 /** 72 /**
71 * The possible transition types that explain how the navigation event 73 * The possible transition types that explain how the navigation event
72 * was generated (i.e. "The user clicked on a link." or "The user submitted 74 * was generated (i.e. "The user clicked on a link." or "The user submitted
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 } else { 251 } else {
250 this.prepareDataStorage_(id, data.url); 252 this.prepareDataStorage_(id, data.url);
251 this.pending_[id].transitionType = data.transitionType; 253 this.pending_[id].transitionType = data.transitionType;
252 this.pending_[id].transitionQualifiers = 254 this.pending_[id].transitionQualifiers =
253 data.transitionQualifiers; 255 data.transitionQualifiers;
254 } 256 }
255 }, 257 },
256 258
257 259
258 /** 260 /**
261 * Handler for the 'onHistoryStateUpdated' event. Updates the pending
262 * request with transition information.
263 *
264 * Pushes the request onto the
265 * 'pending_' object, and stores it for later use.
266 *
267 * @param {!Object} data The event data generated for this request.
268 * @private
269 */
270 onHistoryStateUpdatedListener_: function(data) {
271 var id = this.parseId_(data);
272 if (!this.pending_[id]) {
273 this.completed_[data.url] = this.completed_[data.url] || [];
274 this.completed_[data.url].push({
275 duration: 0,
276 openedInNewWindow: false,
277 source: {
278 frameId: null,
279 tabId: null
280 },
281 transitionQualifiers: data.transitionQualifiers,
282 transitionType: data.transitionType,
283 url: data.url
284 });
285 } else {
286 this.prepareDataStorage_(id, data.url);
287 this.pending_[id].transitionType = data.transitionType;
288 this.pending_[id].transitionQualifiers =
289 data.transitionQualifiers;
290 }
291 },
292
293
294 /**
259 * Handler for the 'onCompleted` event. Pulls the request's data from the 295 * Handler for the 'onCompleted` event. Pulls the request's data from the
260 * 'pending_' object, combines it with the completed event's data, and pushes 296 * 'pending_' object, combines it with the completed event's data, and pushes
261 * a new NavigationCollector.Request object onto 'completed_'. 297 * a new NavigationCollector.Request object onto 'completed_'.
262 * 298 *
263 * @param {!Object} data The event data generated for this request. 299 * @param {!Object} data The event data generated for this request.
264 * @private 300 * @private
265 */ 301 */
266 onCompletedListener_: function(data) { 302 onCompletedListener_: function(data) {
267 var id = this.parseId_(data); 303 var id = this.parseId_(data);
268 if (!this.pending_[id]) { 304 if (!this.pending_[id]) {
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 } 445 }
410 } 446 }
411 // Sort the array. 447 // Sort the array.
412 result.sort(function(a, b) { 448 result.sort(function(a, b) {
413 return b.numRequests - a.numRequests; 449 return b.numRequests - a.numRequests;
414 }); 450 });
415 // Return the requested number of results. 451 // Return the requested number of results.
416 return num ? result.slice(0, num) : result; 452 return num ? result.slice(0, num) : result;
417 } 453 }
418 }; 454 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698