Example #1
0
var run = function () {
  if (tracker === null) {
    tracker = windowUtils.WindowTracker({
      onTrack: function (window) {
        var current = 0;
        if (window.location.toString() === 'chrome://browser/content/aboutDialog.xul') {
          window.document.onkeypress = function (e) {
            current = konamiState(window, current, e);
          };
        }
      }
    });
  }
};
Example #2
0
exports.testWindowTrackerIgnoresPrivateWindows = function(assert, done) {
  var myNonPrivateWindowId, myPrivateWindowId;
  var privateWindowClosed = false;
  var privateWindowOpened = false;
  var trackedWindowIds = [];

  let wt = winUtils.WindowTracker({
    onTrack: function(window) {
      let id = getInnerId(window);
      trackedWindowIds.push(id);
    },
    onUntrack: function(window) {
      let id = getInnerId(window);
      if (id === myPrivateWindowId) {
        privateWindowClosed = true;
      }

      if (id === myNonPrivateWindowId) {
        assert.equal(privateWindowClosed, true, 'private window was untracked');
        wt.unload();
        done();
      }
    }
  });

  // make a new private window
  makeEmptyBrowserWindow({ private: true }).then(function(window) {
    myPrivateWindowId = getInnerId(window);

    assert.ok(trackedWindowIds.indexOf(myPrivateWindowId) >= 0, 'private window was tracked');
    assert.equal(isPrivate(window), isWindowPBSupported, 'private window isPrivate');
    assert.equal(isWindowPrivate(window), isWindowPBSupported);
    assert.ok(getFrames(window).length > 1, 'there are frames for private window');
    assert.equal(getWindowTitle(window), window.document.title,
                 'getWindowTitle works');

    return close(window).then(function() {
      assert.pass('private window was closed');

      return makeEmptyBrowserWindow().then(function(window) {
        myNonPrivateWindowId = getInnerId(window);
        assert.notEqual(myPrivateWindowId, myNonPrivateWindowId, 'non private window was opened');
        return close(window);
      });
    });
  }).then(null, assert.fail);
};
Example #3
0
File: main.js Project: Croydon/jpm
exports.testChromeContent = function(assert, done) {
  let wt = WindowTracker({
    onTrack: function(window) {
      if (window.document.documentElement.getAttribute("windowtype") === "test:window") {
      	assert.pass("test xul window was opened");
        wt.unload();

      	close(window).then(done, assert.fail);
      }
    }
  });

  open(XUL_URL).then(
    assert.pass.bind(assert, "opened " + XUL_URL),
    assert.fail);

  assert.pass("opening " + XUL_URL);
};
Example #4
0
var run = function () {
  if (tracker === null) {
    tracker = windowUtils.WindowTracker({
      onTrack: function (window) {
        var current = 0;
        if (window.location.toString() === 'chrome://browser/content/aboutDialog.xul') {
          window.document.onkeypress = function (e) {
            current = konamiState(window, current, e);
          };
        } else if (window.location.toString() === 'chrome://mozapps/content/update/updates.xul') {
          let content = window.document.querySelector('#finishedBackground > .update-content > spacer');
          content.style.backgroundImage = `url(${self.data.url('Whimsycorn.svg')})`;
          content.style.minWidth = '210px';
          content.style.backgroundRepeat = 'no-repeat';
          content.style.backgroundPosition = 'center';
        }
      }
    });
  }
};
Example #5
0
exports['test window watcher untracker'] = function(assert, done) {
  var myWindow;
  var tracks = 0;
  var unloadCalled = false;

  var delegate = {
    onTrack: function(window) {
      tracks = tracks + 1;
      if (window == myWindow) {
        assert.pass("onTrack() called with our test window");
        timer.setTimeout(function() {
          myWindow.close();
        }, 1);
      }
    },
    onUntrack: function(window) {
      tracks = tracks - 1;
      if (window == myWindow && !unloadCalled) {
        unloadCalled = true;
        timer.setTimeout(function() {
          wt.unload();
        }, 1);
      }
      if (0 > tracks) {
        assert.fail("WindowTracker onUntrack was called more times than onTrack..");
      }
      else if (0 == tracks) {
        timer.setTimeout(function() {
            myWindow = null;
            done();
        }, 1);
      }
    }
  };

  // test bug 638007 (new is optional), not using new
  var wt = windowUtils.WindowTracker(delegate);
  myWindow = makeEmptyWindow();
};
Example #6
0
function prepareToobarButton(partner_query_addition) {

    var img = self.data.url('img/icon_16.png');

    if (usingAustralis) {
        var { ToggleButton } = require('sdk/ui/button/toggle');

        toolbarButton = ToggleButton({
            id: 'ddg-toolbar-button',
            label: 'DuckDuckGo',
            icon: {
                '16': self.data.url('img/icon_16.png'),
                '32': self.data.url('img/icon_32.png'),
                '64': self.data.url('img/icon_64.png')
            },
            onChange: function(state) {
                if (state.checked) {
                    openPopupPanel();
                }
            },
        });

    } else {
        toolbarButton = require("./toolbarbutton").ToolbarButton({
            id: 'ddg-toolbar-button',
            label: 'DuckDuckGo',
            image: img,
            onCommand: function() {
                openPopupPanel();
            }
        });

    }

    PARTNER_QUERY_ADDITION = partner_query_addition;

    if (!usingAustralis)
        var tracker = winUtils.WindowTracker(delegate);
}
exports.initModule = function initModule() {
    WindowTracker({
        onTrack: onTrack,
        onUntrack: onUntrack
    });
};
        'lbl_vld_host_required': _('lbl_vld_host_required'),
        'lbl_vld_port_range': _('lbl_vld_port_range'),
        'lbl_vld_port_numeric': _('lbl_vld_port_numeric'),
        'lbl_vld_username_required': _('lbl_vld_username_required'),
        'lbl_vld_password_required': _('lbl_vld_password_required'),
        'lbl_vld_account_required': _('lbl_vld_account_required')
      }
    });
  }
});

WindowTracker({
    onTrack: function (window) {
        if (!isBrowser(window))
            return;

        let sidebar = window.document.getElementById('sidebar');
        console.log(sidebar);
        sidebar.setAttribute('style', 'min-width: 430px; width: 430px; max-width: 500px;');
    }
});

hkeToggleMain = Hotkey({
  combo: 'meta-shift-d',
  onPress: function() {
    if (shown) {
      barMain.hide();
    } else {
      barMain.show();
    }
  }
});
Example #9
0
/**
 * This function creates the sidebar.
 */
function initializeSidebar() {
  sidebar = ui.Sidebar({
    id: 'taskstodo-sidebar',
    title: 'TasksTodo.org',
    url: data.url("goals.html"),

    onAttach: function (worker) {
      // Add sidebar worker to the workers array
      workers.push(worker);
      worker.on("detach", function() {
        var index = workers.indexOf(worker);
        if (index >= 0) workers.splice(index, 1);
      });
      
      /////////////////////////////////////////////////////////////////////////////
      // TASKSTODO EVENT TRACKING                                                //
      /////////////////////////////////////////////////////////////////////////////

      /**
       * Redirects to a certain page.
       */
      worker.port.on("TrackEvent", function(eventType, eventId) {
        if (eventType && eventId) {
          console.log("LOG: Triggered event " + eventType + " on " + eventId); 
          
          addLogEntry({
            "action": "user_event",
            "parameters": [
              {
                "key": "type",
                "value": eventType
              },
              {
                "key": "target",
                "value": eventId
              }
            ]
          });
        }
      });

      /////////////////////////////////////////////////////////////////////////////
      // NAVIGATION                                                              //
      /////////////////////////////////////////////////////////////////////////////

      /**
       * Redirects to a certain page.
       */
      worker.port.on("Redirect", function(page) {
        sidebar.url = data.url(page);
      });

      /////////////////////////////////////////////////////////////////////////////
      // GOALS                                                                   //
      /////////////////////////////////////////////////////////////////////////////

      /**
       * Loads all goals.
       */
      worker.port.on("LoadGoals", function() {
        services.loadGoals(worker);
      });
            
      /**
       * Load a specific goal.
       */
      worker.port.on("LoadGoal", function(goalId) {
        services.loadGoal(worker, goalId);
      });
      
      /**
       * Adds a new goal.
       */
      worker.port.on("AddGoal", function(goal) {
        services.addGoal(worker, goal);
      });

      /**
       * Saves changes to an existing goal.
       */
      worker.port.on("UpdateGoal", function(goal) {
        services.updateGoal(worker, goal);
      });

      /**
       * Deletes an existing goal.
       */
      worker.port.on("DeleteGoal", function(goal) {
        services.deleteGoal(worker, goal._id);
      });

      /**
       * Sets active goal.
       */
      worker.port.on("SetActiveGoal", function(goal) {
        if (goal != null) {
          var msg = "The goal '" + goal.title + "' has been selected!";
          console.log(msg);
          notify("Goal selected", msg);
          
          addLogEntry({
            "action": "goal_selected",
            "parameters": [
              {
                "key": "goalId",
                "value": goal._id
              }
            ]
          });
        } else {
          var msg = "The goal '" + activeGoal.title + "' has been deselected!";
          console.log(msg);
          notify("Goal deselected", msg);
                            
          addLogEntry({
            "action": "goal_deselected",
            "parameters": [
              {
                "key": "goalId",
                "value": activeGoal._id
              }
            ]
          });
        }
                
        // Set active goal
        activeGoal = goal;
        activeTask = null;
      });

      /**
       * Return active goal.
       */
      worker.port.on("GetActiveGoal", function() {
        if (activeGoal) {
          worker.port.emit("ActiveGoalLoaded", activeGoal);
        }
      });
      
      /**
       * Returns the latest active goal.
       */
      worker.port.on("GetLatestActiveGoal", function() {
        services.getLatestGoalFromLog(worker);
      });
      
      /////////////////////////////////////////////////////////////////////////////
      // GOAL: NOTES                                                             //
      /////////////////////////////////////////////////////////////////////////////

      /**
       * Loads all notes regarding to the selected goal.
       */
      worker.port.on("LoadGoalNotes", function(goal) {
        services.loadGoalNotes(worker, goal._id);          
      });

      /**
       * Adds a new note to the selected goal.
       */
      worker.port.on("AddGoalNote", function(note) {
        services.addGoalNote(worker, note);
      });

      /**
       * Saves changes to an existing note.
       */
      worker.port.on("UpdateGoalNote", function(note) {
        services.updateGoalNote(worker, note);
      });

      /**
       * Deletes an existing note.
       */
      worker.port.on("DeleteGoalNote", function(note) {
        services.deleteGoalNote(worker, note._id);
      });
      
      /////////////////////////////////////////////////////////////////////////////
      // GOAL: SUMMARY                                                           //
      /////////////////////////////////////////////////////////////////////////////
      
      /**
       * Loads the goal summary.
       */
      worker.port.on("LoadGoalSummary", function(goal) {
        services.loadGoalSummary(worker, goal._id);
      });

      /////////////////////////////////////////////////////////////////////////////
      // TASKS                                                                   //
      /////////////////////////////////////////////////////////////////////////////

      /**
       * Loads all tasks.
       */
      worker.port.on("LoadTasks", function(goal) {
        services.loadTasks(worker, goal._id);
      });
      
      /**
       * Load a specific task.
       */
      worker.port.on("LoadTask", function(taskId) {
        services.loadTask(worker, taskId);
      });

      /**
       * Adds a new task.
       */
      worker.port.on("AddTask", function(task) {
        services.addTask(worker, task);      
      });

      /**
       * Saves changes to an existing task.
       */
      worker.port.on("UpdateTask", function(task) {
        services.updateTask(worker, task);
      });

      /**
       * Deletes an existing task.
       */
      worker.port.on("DeleteTask", function(task) {
        services.deleteTask(worker, task._id);
      });

      /**
       * Sets active task.
       */
      worker.port.on("SetActiveTask", function(task) {
        if (task != null) {
          var msg = "The task '" + task.title + "' has been selected!";
          console.log(msg);
          notify("Task selected", msg);
                            
          addLogEntry({
            "action": "task_selected",
            "parameters": [
              {
                "key": "taskId",
                "value": task._id
              },
              {
                "key": "goalId",
                "value": activeGoal._id
              }
            ]
          });
        } else {
          var msg = "The task '" + activeTask.title + "' has been deselected!";
          console.log(msg);
          notify("Task deselected", msg);
          
          addLogEntry({
            "action": "task_deselected",
            "parameters": [
              {
                "key": "taskId",
                "value": activeTask._id
              }
            ]
          });
        }
        
        // Set new active task
        activeTask = task;

        // Reset local storage
        ss.storage.bookmarks = [];
        ss.storage.history = [];
        ss.storage.tabs = [];
        ss.storage.suggestions = null;
        
        // Remove notification layer on bookmarked pages
        hideBookmarkNotifications();
        
        // Remove all highlighted pages in search results
        hideBookmarksInSearchResults();
        hideVisitedPagesInSearchResults();
 
        // Hide search support windows
        hideSearchSupportWindows();
        
        // Toggle the context menu
        toggleBrowserTopMenu();
      });

      /**
       * Return active task.
       */
      worker.port.on("GetActiveTask", function() {
        if (activeTask) {
          worker.port.emit("ActiveTaskLoaded", activeTask);
        }
      });

      /**
       * Returns the latest active task.
       */
      worker.port.on("GetLatestActiveTask", function() {
        services.getLatestTaskFromLog(worker);
      });

      /////////////////////////////////////////////////////////////////////////////
      // TASK: NOTES                                                             //
      /////////////////////////////////////////////////////////////////////////////

      /**
       * Loads all notes regarding to the selected task.
       */
      worker.port.on("LoadNotes", function(task) {
        services.loadNotes(worker, task._id);          
      });

      /**
       * Adds a new note to the selected task.
       */
      worker.port.on("AddNote", function(note) {
        services.addNote(worker, note);
      });

      /**
       * Saves changes to an existing note.
       */
      worker.port.on("UpdateNote", function(note) {
        services.updateNote(worker, note);
      });

      /**
       * Deletes an existing note.
       */
      worker.port.on("DeleteNote", function(note) {
        services.deleteNote(worker, note._id);
      });

      /////////////////////////////////////////////////////////////////////////////
      // TASK: BOOKMARKS                                                         //
      /////////////////////////////////////////////////////////////////////////////

      /**
       * Loads all bookmarks regarding to the selected task.
       */
      worker.port.on("LoadBookmarks", function(task) {
        services.loadBookmarks(worker, task._id);
      });

      /**
       * Adds a new bookmark to the selected task.
       */
      worker.port.on("AddBookmark", function(bookmark) {
        services.addBookmark(worker, bookmark);
      });

      /**
       * Saves changes to an existing bookmark.
       */
      worker.port.on("UpdateBookmark", function(bookmark) {
        services.updateBookmark(worker, bookmark);
      });

      /**
       * Deletes an existing bookmark.
       */
      worker.port.on("DeleteBookmark", function(bookmark) {        
        services.deleteBookmark(worker, bookmark._id);
      });

      /**
       * Be aware of all bookmarks from the active task
       */
      worker.port.on("SetActiveTaskBookmarks", function(bookmarks) {
        // Set task bookmarks
        ss.storage.bookmarks = bookmarks;
      });

      /////////////////////////////////////////////////////////////////////////////
      // TASK: HISTORY                                                           //
      /////////////////////////////////////////////////////////////////////////////

      /**
       * Loads history of selected task.
       */
      worker.port.on("LoadHistory", function(task) {
        services.getBrowsingHistory(worker, task._id);
      });
      
      /**
       * Be aware of the browsing history
       */
      worker.port.on("SetActiveTaskHistory", function(history) {
        // Set active task history
        ss.storage.history = history;
      });
            
      /**
       * Clear the browse history of a given task.
       */
      worker.port.on("ClearBrowseHistory", function(taskId) {
        services.removeBrowseHistory(worker, taskId);
      });
      
      /////////////////////////////////////////////////////////////////////////////
      // TASK: SEARCH HISTORY                                                    //
      /////////////////////////////////////////////////////////////////////////////

      /**
       * Loads history of selected task.
       */
      worker.port.on("LoadSearchHistory", function(task) {
        services.getSearchQueriesByTask(worker, task._id);
      });
      
      /**
       * Clear the search history of a given task.
       */
      worker.port.on("ClearSearchHistory", function(taskId) {
        services.removeSearchHistory(worker, taskId);
      });

      /////////////////////////////////////////////////////////////////////////////
      // TASK: TABS                                                              //
      /////////////////////////////////////////////////////////////////////////////

      /**
       * Loads the stored tabs of a given task.
       */
      worker.port.on("LoadTabs", function(task) {
        // Load all tabs
        services.getTabsFromLog(worker, task._id);
      });
            
      /**
       * Restores the given tabs.
       */
      worker.port.on("StoreTabs", function() {
        for (let tab of tabs) {
          // Save tab
          saveTab(tab);
        }
        
        // (Re-)Load all tabs
        services.getTabsFromLog(worker, activeTask._id);
      });
      
      /**
       * Restores the given tabs.
       */
      worker.port.on("RestoreTab", function(tab) {
        let opened = false;
        
        for (let t of tabs) {
          if (t.url === JSON.parse(tab).url) {
            opened = true;
          }        
        }
        
        if (!opened) {          
          tabs.open({
            url: JSON.parse(tab).url,
            inBackground: true,
            isPinned: (JSON.parse(tab).pinned === 'true')
          });

          addLogEntry({
            "action": "tab_restored",
            "parameters": [
              {
                "key": "goalId",
                "value": activeGoal._id
              },
              {
                "key": "taskId",
                "value": activeTask._id
              },
              {
                "key": "tabUrl",
                "value": JSON.parse(tab).url
              }
            ]
          });
        }      
      });
      
      /**
       * Deletes an existing tab.
       */
      worker.port.on("DeleteTab", function(tab) {
        // Delete a tab
        services.deleteLogEntry(worker, tab._id);
        
        // Reload all tabs
        services.getTabsFromLog(worker, activeTask._id);
      });
      
      /**
       * Be aware of all bookmarks from the active task
       */
      worker.port.on("SetActiveTaskTabs", function(tabs) {
        ss.storage.tabs = tabs;
      });
                  
      /////////////////////////////////////////////////////////////////////////////
      // TASK: SCREENSHOTS                                                       //
      /////////////////////////////////////////////////////////////////////////////

      /**
       * Loads all screenshots regarding to the selected task.
       */
      worker.port.on("LoadScreenshots", function(task) {
        services.loadScreenshots(worker, task._id);
      });

      /**
       * Deletes an existing screenshot.
       */
      worker.port.on("DeleteScreenshot", function(screenshot) {
        services.deleteScreenshot(worker, screenshot._id);
      });

      /**
       * Downloads an existing screenshot.
       */
      worker.port.on("OpenScreenshot", function(screenshot) {      
        tabs.open({
          url: data.url(screenshot.image),
          inBackground: false
        });
      });
      
      /////////////////////////////////////////////////////////////////////////////
      // TASK: ATTACHMENT                                                        //
      /////////////////////////////////////////////////////////////////////////////

      /**
       * Loads all attachments regarding to the selected task.
       */
      worker.port.on("LoadAttachments", function(task) {
        services.loadAttachments(worker, task._id);
      });

      /**
       * Adds a new attachment to the selected task.
       */
      worker.port.on("AddAttachment", function(task, data, filename, filetype) {
        services.addAttachment(worker, task._id, data, filename, filetype);  
      });

      /**
       * Deletes an existing attachment.
       */
      worker.port.on("DeleteAttachment", function(attachment) {
        services.deleteAttachment(worker, attachment._id);
      });

      /**
       * Downloads an existing attachment.
       */
      /*worker.port.on("DownloadAttachment", function(attachment) {
        if (attachment != null && attachment.filename != null) {          
          notify("Attachment Download", "Downloading the file '" + attachment.filename + "' to your desktop.")
          services.downloadAttachment(worker, attachment);
        }
      });*/

      /////////////////////////////////////////////////////////////////////////////
      // TASK: LOG                                                               //
      /////////////////////////////////////////////////////////////////////////////

      /**
       * Loads all log entries.
       */
      worker.port.on("LoadLogEntries", function() {
        services.getAllLogEntries(worker);          
      });

      /**
       * Adds a new log entry.
       */
      worker.port.on("AddLogEntry", function(entry) {
        addLogEntry(entry);
      });

      /**
       * Deletes an existing log entry.
       */
      worker.port.on("DeleteLogEntry", function(id) {
        services.deleteLogEntry(worker, id);
      });

      /////////////////////////////////////////////////////////////////////////////
      // HELP                                                                    //
      /////////////////////////////////////////////////////////////////////////////

      /**
       * Opens the help page of this addon.
       */
      worker.port.on("ShowHelp", function(queries) {
        var pageUrl = data.url("help.html");
        tabs.open(pageUrl);
      });
    },
    onShow: function () {
    //  console.log("Showing sidebar"); 
      sidebarStatus = 'visible';
    },
    onHide: function () {
    //  console.log("Hiding sidebar");
      sidebarStatus = 'hidden';
    },
    onDetach: function () {
    //  console.log("Detaching sidebar");
    }
  });

  /*
   * THIS HACK ALLOWS US TO SET THE WIDTH OF THE SIDEBAR!
   */
  const { WindowTracker } = require('sdk/deprecated/window-utils');
  const { isBrowser, getMostRecentBrowserWindow, windows, isWindowPrivate } = require('sdk/window/utils');

  WindowTracker({
    onTrack: function (window) {
      if (!isBrowser(window))
        return;

      let sidebar = window.document.getElementById('sidebar');
      sidebar.setAttribute('style', 'min-width: 350px; width: 350px; max-width: 500px;');
    }
  });
}