Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support moz-action:switchtotab #4

Open
piroor opened this issue Jan 9, 2013 · 3 comments
Open

Support moz-action:switchtotab #4

piroor opened this issue Jan 9, 2013 · 3 comments

Comments

@piroor
Copy link
Owner

piroor commented Jan 9, 2013

http://mxr.mozilla.org/mozilla-central/source/toolkit/components/places/nsPlacesAutoComplete.js#1065

1065   _processRow: function PAC_processRow(aRow)
1066   {
...
1070     let openPageCount = aRow.getResultByIndex(kQueryIndexOpenPageCount) || 0;
1071 
1072     // If actions are enabled and the page is open, add only the switch-to-tab
1073     // result.  Otherwise, add the normal result.
1074     let [url, action] = this._enableActions && openPageCount > 0 ?
1075                         ["moz-action:switchtab," + escapedEntryURL, "action "] :
1076                         [escapedEntryURL, ""];

The count is registered by this SQL:
http://mxr.mozilla.org/mozilla-central/source/toolkit/components/places/nsPlacesAutoComplete.js#460

460   this._registerOpenPageQuerySQL = "INSERT OR REPLACE INTO moz_openpages_temp "
461                                  +   "(url, open_count) "
462                                  + "VALUES (:page_url, "
463                                  +   "IFNULL("
464                                  +     "("
465                                  +        "SELECT open_count + 1 "
466                                  +        "FROM moz_openpages_temp "
467                                  +        "WHERE url = :page_url "
468                                  +      "), "
469                                  +     "1"
470                                  +   ")"
471                                  + ")";
472   XPCOMUtils.defineLazyGetter(this, "_registerOpenPageQuery", function() {
473     return this._db.createAsyncStatement(this._registerOpenPageQuerySQL);
474   });

However, the table moz_openpages_temp is in an inaccessible connection.

http://mxr.mozilla.org/mozilla-central/source/toolkit/components/places/nsPlacesAutoComplete.js#302

302   XPCOMUtils.defineLazyGetter(this, "_db", function() {
303     // Get a cloned, read-only version of the database.  We'll only ever write
304     // to our own in-memory temp table, and having a cloned copy means we do not
305     // run the risk of our queries taking longer due to the main database
306     // connection performing a long-running task.
307     let db = Cc["@mozilla.org/browser/nav-history-service;1"].
308              getService(Ci.nsPIPlacesDatabase).
309              DBConnection.
310              clone(true);
...
319     // Create our in-memory tables for tab tracking.
320     initTempTable(db);
@piroor
Copy link
Owner Author

piroor commented Jan 9, 2013

http://mxr.mozilla.org/mozilla-central/source/browser/base/content/tabbrowser.xml#622

623                 if (this.mBrowser.registeredOpenURI) {
624                   autocomplete.unregisterOpenPage(this.mBrowser.registeredOpenURI);
625                   delete this.mBrowser.registeredOpenURI;
626                 }
627                 if (!isBlankPageURL(aLocation.spec)
628 #ifdef MOZ_PER_WINDOW_PRIVATE_BROWSING
629                     // Tabs in private windows aren't registered as "Open" so
630                     // that they don't appear as switch-to-tab candidates.
631                     && !PrivateBrowsingUtils.isWindowPrivate(window)
632 #endif
633                     ) {
634                   autocomplete.registerOpenPage(aLocation);
635                   this.mBrowser.registeredOpenURI = aLocation;

Open page count is updated on "onLocationChange" of tab progress listeners. By custom tab progress listeners, we can emulate it.

@piroor
Copy link
Owner Author

piroor commented Jan 10, 2013

It is too much: adding progress listeners for the location bar. Is there any alternative way?

Points:

  • On searching, we have to restrict search results to "only open pages".
    Is it possible that list open pages quickly without temporary table?
  • On listing, we have to use "moz-action:" URI instead of normal URI.
    Is it possible that checking open state of a page without temporary table?

@piroor
Copy link
Owner Author

piroor commented Jan 10, 2013

Currently there is no way, because:

  • It is an XPCOM component, not a JS code module. So, we have no way to access the instance having internal property "_db".
  • There is no API to get open count. Firefox gets the count directly by SQL.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant