@Override
 public void onTabChanged(Tab tab, Tabs.TabEvents msg, Object data) {
   switch (msg) {
     case LOCATION_CHANGE:
       if (Tabs.getInstance().isSelectedTab(tab)) {
         maybeCancelFaviconLoad(tab);
       }
       // fall through
     case SELECTED:
       if (Tabs.getInstance().isSelectedTab(tab)) {
         if ("about:home".equals(tab.getURL())) showAboutHome();
         else hideAboutHome();
       }
       break;
     case LOAD_ERROR:
     case START:
     case STOP:
     case MENU_UPDATED:
       if (Tabs.getInstance().isSelectedTab(tab)) {
         invalidateOptionsMenu();
       }
       break;
   }
   super.onTabChanged(tab, msg, data);
 }
  @Override
  protected void initializeChrome(String uri, boolean isExternalURL) {
    super.initializeChrome(uri, isExternalURL);

    mBrowserToolbar.updateBackButton(false);
    mBrowserToolbar.updateForwardButton(false);

    mDoorHangerPopup.setAnchor(mBrowserToolbar.mFavicon);

    if (isExternalURL || mRestoreMode != RESTORE_NONE) {
      mAboutHomeStartupTimer.cancel();
    }

    if (!mIsRestoringActivity) {
      if (!isExternalURL) {
        // show about:home if we aren't restoring previous session
        if (mRestoreMode == RESTORE_NONE) {
          Tab tab = Tabs.getInstance().loadUrl("about:home", Tabs.LOADURL_NEW_TAB);
        } else {
          hideAboutHome();
        }
      } else {
        int flags = Tabs.LOADURL_NEW_TAB | Tabs.LOADURL_USER_ENTERED;
        Tabs.getInstance().loadUrl(uri, flags);
      }
    }
  }
Exemple #3
0
 private void connectToGecko() {
   GeckoThread.setLaunchState(GeckoThread.LaunchState.GeckoRunning);
   Tab selectedTab = Tabs.getInstance().getSelectedTab();
   if (selectedTab != null)
     Tabs.getInstance().notifyListeners(selectedTab, Tabs.TabEvents.SELECTED);
   geckoConnected();
   GeckoAppShell.setLayerClient(getLayerClientObject());
   GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Viewport:Flush", null));
 }
Exemple #4
0
  public JobConfig toJobConfig(CRJob crJob) {
    JobConfig jobConfig = new JobConfig(crJob.getName());
    if (crJob.getEnvironmentVariables() != null)
      for (CREnvironmentVariable crEnvironmentVariable : crJob.getEnvironmentVariables()) {
        jobConfig.getVariables().add(toEnvironmentVariableConfig(crEnvironmentVariable));
      }

    List<CRTask> crTasks = crJob.getTasks();
    Tasks tasks = jobConfig.getTasks();
    if (crTasks != null)
      for (CRTask crTask : crTasks) {
        tasks.add(toAbstractTask(crTask));
      }

    Tabs tabs = jobConfig.getTabs();
    if (crJob.getTabs() != null)
      for (CRTab crTab : crJob.getTabs()) {
        tabs.add(toTab(crTab));
      }

    Resources resources = jobConfig.resources();
    if (crJob.getResources() != null)
      for (String crResource : crJob.getResources()) {
        resources.add(new Resource(crResource));
      }

    ArtifactPlans artifactPlans = jobConfig.artifactPlans();
    if (crJob.getArtifacts() != null)
      for (CRArtifact crArtifact : crJob.getArtifacts()) {
        artifactPlans.add(toArtifactPlan(crArtifact));
      }

    ArtifactPropertiesGenerators artifactPropertiesGenerators = jobConfig.getProperties();
    if (crJob.getArtifactPropertiesGenerators() != null)
      for (CRPropertyGenerator crPropertyGenerator : crJob.getArtifactPropertiesGenerators()) {
        artifactPropertiesGenerators.add(
            new ArtifactPropertiesGenerator(
                crPropertyGenerator.getName(),
                crPropertyGenerator.getSrc(),
                crPropertyGenerator.getXpath()));
      }

    if (crJob.isRunOnAllAgents()) jobConfig.setRunOnAllAgents(true);
    else {
      Integer count = crJob.getRunInstanceCount();
      if (count != null) jobConfig.setRunInstanceCount(count);
      // else null - meaning simple job
    }

    if (crJob.getTimeout() != null) jobConfig.setTimeout(Integer.toString(crJob.getTimeout()));
    // else null - means default server-wide timeout

    return jobConfig;
  }
 public void refresh() {
   Tab tab = Tabs.getInstance().getSelectedTab();
   if (tab != null) {
     String url = tab.getURL();
     setTitle(tab.getDisplayTitle());
     setFavicon(tab.getFavicon());
     setSecurityMode(tab.getSecurityMode());
     setReaderVisibility(tab.getReaderEnabled());
     setProgressVisibility(tab.getState() == Tab.STATE_LOADING);
     setShadowVisibility((url == null) || !url.startsWith("about:"));
     updateTabCount(Tabs.getInstance().getCount());
     updateBackButton(tab.canDoBack());
     updateForwardButton(tab.canDoForward());
   }
 }
Exemple #6
0
 /**
  * Get the active/visible Browser.
  *
  * @return The current selected Browser.
  */
 public Browser getCurrentBrowser() {
   Tab tab = Tabs.getInstance().getSelectedTab();
   if (tab != null) {
     return new Browser(tab.getId());
   }
   return null;
 }
Exemple #7
0
 /**
  * Add a Browser to the GeckoView container.
  *
  * @param url The URL resource to load into the new Browser.
  */
 public Browser addBrowser(String url) {
   Tab tab = Tabs.getInstance().loadUrl(url, Tabs.LOADURL_NEW_TAB);
   if (tab != null) {
     return new Browser(tab.getId());
   }
   return null;
 }
Exemple #8
0
  // This callback is automatically executed on the UI thread.
  @Override
  public void onTabChanged(final Tab tab, final Tabs.TabEvents msg, final Object data) {
    switch (msg) {
      case CLOSED:
        // Remove any doorhangers for a tab when it's closed (make
        // a temporary set to avoid a ConcurrentModificationException)
        HashSet<DoorHanger> doorHangersToRemove = new HashSet<DoorHanger>();
        for (DoorHanger dh : mDoorHangers) {
          if (dh.getTabId() == tab.getId()) doorHangersToRemove.add(dh);
        }
        for (DoorHanger dh : doorHangersToRemove) {
          removeDoorHanger(dh);
        }
        break;

      case LOCATION_CHANGE:
        // Only remove doorhangers if the popup is hidden or if we're navigating to a new URL
        if (!isShowing() || !data.equals(tab.getURL())) removeTransientDoorHangers(tab.getId());

        // Update the popup if the location change was on the current tab
        if (Tabs.getInstance().isSelectedTab(tab)) updatePopup();
        break;

      case SELECTED:
        // Always update the popup when a new tab is selected. This will cover cases
        // where a different tab was closed, since we always need to select a new tab.
        updatePopup();
        break;
    }
  }
Exemple #9
0
 /**
  * Check to see if the Browser has session history and can go forward to a new page.
  *
  * @return A boolean flag indicating if forward session exists. This method will likely be
  *     removed and replaced by a callback in GeckoViewContent
  */
 public boolean canGoForward() {
   Tab tab = Tabs.getInstance().getTab(mId);
   if (tab != null) {
     return tab.canDoForward();
   }
   return false;
 }
Exemple #10
0
  private void showSuggestionsOptIn() {
    mSuggestionsOptInPrompt =
        LayoutInflater.from(mContext)
            .inflate(R.layout.awesomebar_suggestion_prompt, (LinearLayout) getView(), false);
    GeckoTextView promptText =
        (GeckoTextView) mSuggestionsOptInPrompt.findViewById(R.id.suggestions_prompt_title);
    promptText.setText(
        getResources().getString(R.string.suggestions_prompt, mSearchEngines.get(0).name));
    Tab tab = Tabs.getInstance().getSelectedTab();
    if (tab != null) promptText.setPrivateMode(tab.isPrivate());

    final View yesButton = mSuggestionsOptInPrompt.findViewById(R.id.suggestions_prompt_yes);
    final View noButton = mSuggestionsOptInPrompt.findViewById(R.id.suggestions_prompt_no);
    OnClickListener listener =
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            // Prevent the buttons from being clicked multiple times (bug 816902)
            yesButton.setOnClickListener(null);
            noButton.setOnClickListener(null);

            setSuggestionsEnabled(v == yesButton);
          }
        };
    yesButton.setOnClickListener(listener);
    noButton.setOnClickListener(listener);

    mSuggestionsOptInPrompt.setVisibility(View.GONE);
    ((LinearLayout) getView()).addView(mSuggestionsOptInPrompt, 0);
  }
Exemple #11
0
  public boolean insertBefore(Component child, Component refChild) {
    if (child instanceof Tabs) {
      if (super.insertBefore(child, refChild)) {
        _tabs = (Tabs) child;
        for (Iterator it = _tabs.getChildren().iterator(); it.hasNext(); ) {
          final Tab tab = (Tab) it.next();
          if (tab.isSelected()) {
            _seltab = tab;
            break;
          }
        }

        addTabsListeners();
        return true;
      }
    } else if (child instanceof Tabpanels) {
      if (super.insertBefore(child, refChild)) {
        _tabpanels = (Tabpanels) child;
        return true;
      }
    } else if (child instanceof Toolbar) {
      if (super.insertBefore(child, refChild)) {
        _toolbar = (Toolbar) child;
        return true;
      }
    } else {
      return super.insertBefore(child, refChild);
      // impossible but make it more extensible
    }
    return false;
  }
Exemple #12
0
  private void styleSelectedTab() {
    int selIndex = mViewPager.getCurrentItem();
    TabWidget tabWidget = getTabWidget();
    boolean isPrivate = false;

    if (mTarget != null && mTarget.equals(AwesomeBar.Target.CURRENT_TAB.name())) {
      Tab tab = Tabs.getInstance().getSelectedTab();
      if (tab != null) isPrivate = tab.isPrivate();
    }

    for (int i = 0; i < tabWidget.getTabCount(); i++) {
      GeckoTextView view = (GeckoTextView) tabWidget.getChildTabViewAt(i);
      if (isPrivate) {
        view.setPrivateMode((i == selIndex) ? false : true);
      } else {
        if (i == selIndex) view.resetTheme();
        else if (mActivity.getLightweightTheme().isEnabled())
          view.setTheme(mActivity.getLightweightTheme().isLightTheme());
        else view.resetTheme();
      }

      if (i == selIndex) continue;

      if (i == (selIndex - 1)) view.getBackground().setLevel(1);
      else if (i == (selIndex + 1)) view.getBackground().setLevel(2);
      else view.getBackground().setLevel(0);
    }

    if (selIndex == 0) findViewById(R.id.tab_widget_left).getBackground().setLevel(1);
    else findViewById(R.id.tab_widget_left).getBackground().setLevel(0);

    if (selIndex == (tabWidget.getTabCount() - 1))
      findViewById(R.id.tab_widget_right).getBackground().setLevel(2);
    else findViewById(R.id.tab_widget_right).getBackground().setLevel(0);
  }
  public BrowserToolbar(Context context) {
    mContext = context;
    mInflater = LayoutInflater.from(context);

    sActionItems = new ArrayList<View>();
    Tabs.registerOnTabsChangedListener(this);
  }
Exemple #14
0
 /**
  * Load <code>url</code> using reflection and the internal <code>org.mozilla.gecko.Tabs</code>
  * API.
  *
  * <p>This method does not wait for any confirmation from Gecko before returning.
  */
 protected final void loadUrl(final String url) {
   try {
     Tabs.getInstance().loadUrl(url);
   } catch (Exception e) {
     mAsserter.dumpLog("Exception in loadUrl", e);
     throw new RuntimeException(e);
   }
 }
Exemple #15
0
 /** Adds _listener to all {@link Tab} instances. */
 private void addTabsListeners() {
   if (_tabs != null) {
     for (Iterator it = _tabs.getChildren().iterator(); it.hasNext(); ) {
       final Tab tab = (Tab) it.next();
       tab.addEventListener(Events.ON_SELECT, _listener);
     }
   }
 }
Exemple #16
0
 /**
  * Get the list of current Browsers in the GeckoView container.
  *
  * @return An unmodifiable List of Browser objects.
  */
 public List<Browser> getBrowsers() {
   ArrayList<Browser> browsers = new ArrayList<Browser>();
   Iterable<Tab> tabs = Tabs.getInstance().getTabsInOrder();
   for (Tab tab : tabs) {
     browsers.add(new Browser(tab.getId()));
   }
   return Collections.unmodifiableList(browsers);
 }
Exemple #17
0
 public void setTarget(String target) {
   mTarget = target;
   styleSelectedTab();
   if (mTarget.equals(AwesomeBar.Target.CURRENT_TAB.name())) {
     Tab tab = Tabs.getInstance().getSelectedTab();
     if (tab != null && tab.isPrivate()) mBackground.setPrivateMode(true);
   }
 }
Exemple #18
0
  @Override
  public void requestZoomedViewRender() {
    if (stopUpdateView) {
      return;
    }
    // remove pending runnable
    ThreadUtils.removeCallbacksFromUiThread(requestRenderRunnable);

    // "requestZoomedViewRender" can be called very often by Gecko (endDrawing in LayerRender)
    // without
    // any thing changed in the zoomed area (useless calls from the "zoomed area" point of view).
    // "requestZoomedViewRender" can take time to re-render the zoomed view, it depends of the
    // complexity
    // of the html on this area.
    // To avoid to slow down the application, the 2 following cases are tested:

    // 1- Last render is still running, plan another render later.
    if (isRendering()) {
      // post a new runnable DELAY_BEFORE_NEXT_RENDER_REQUEST_MS later
      // We need to post with a delay to be sure that the last call to requestZoomedViewRender will
      // be done.
      // For a static html page WITHOUT any animation/video, there is a last call to endDrawing and
      // we need to make
      // the zoomed render on this last call.
      ThreadUtils.postDelayedToUiThread(requestRenderRunnable, DELAY_BEFORE_NEXT_RENDER_REQUEST_MS);
      return;
    }

    // 2- Current render occurs too early, plan another render later.
    if (renderFrequencyTooHigh()) {
      // post a new runnable DELAY_BEFORE_NEXT_RENDER_REQUEST_MS later
      // We need to post with a delay to be sure that the last call to requestZoomedViewRender will
      // be done.
      // For a page WITH animation/video, the animation/video can be stopped, and we need to make
      // the zoomed render on this last call.
      ThreadUtils.postDelayedToUiThread(requestRenderRunnable, DELAY_BEFORE_NEXT_RENDER_REQUEST_MS);
      return;
    }

    startTimeReRender = System.nanoTime();
    // Allocate the buffer if it's the first call.
    // Change the buffer size if it's not the right size.
    updateBufferSize();

    int tabId = Tabs.getInstance().getSelectedTab().getId();

    ImmutableViewportMetrics metrics = layerView.getViewportMetrics();
    PointF origin = metrics.getOrigin();

    final int xPos = (int) origin.x + lastPosition.x;
    final int yPos = (int) origin.y + lastPosition.y;

    GeckoEvent e =
        GeckoEvent.createZoomedViewEvent(
            tabId, xPos, yPos, viewWidth, viewHeight, zoomFactor * metrics.zoomFactor, buffer);
    GeckoAppShell.sendEventToGecko(e);
  }
  DoorHangerPopup(GeckoApp activity) {
    super(activity);

    mDoorHangers = new HashSet<DoorHanger>();

    EventDispatcher.getInstance()
        .registerGeckoThreadListener(this, "Doorhanger:Add", "Doorhanger:Remove");
    Tabs.registerOnTabsChangedListener(this);
  }
Exemple #20
0
 @Override
 public boolean activate() {
   int index = 0;
   final Tile[] tiles = GlobalConstant.TILE_ROCKS[Checks.isGold()];
   for (int i = 1; i < tiles.length; i++) {
     if (Calculations.distanceTo(tiles[i]) < Calculations.distanceTo(tiles[index])) index = i;
   }
   if (GlobalConstant.WIELDED_ID != -1
       && (Tabs.getCurrent().equals(Tabs.INVENTORY) || Tabs.getCurrent().equals(Tabs.ATTACK))
       && Settings.get(300) == 1000) {
     if (Checks.getLP() < Skills.getRealLevel(Skills.CONSTITUTION) * 10 - 200) return true;
   }
   return !Banker.isDepositOpen()
       && ((inCombat() /* && Calculations.distanceTo(tiles[index]) < 8 && !Inventory.isFull()*/)
           || Checks.isOutside()
           || (GlobalConstant.KEEP_ALIVE
               && Checks.getLP() < Skills.getRealLevel(Skills.CONSTITUTION) * 0.4f * 10));
 }
Exemple #21
0
 public void onClose() {
   if (onCloseHandler != null) onCloseHandler.onClose(this);
   else {
     Tab tab = this.getLinkedTab();
     Tabbox tabbox = (Tabbox) tab.getTabbox();
     if (tabbox.getSelectedTab() == tab) {
       Tabs tabs = (Tabs) tabbox.getTabs();
       List childs = tabs.getChildren();
       for (int i = 0; i < childs.size(); i++) {
         if (childs.get(i) == tab) {
           if (i > 0) tabbox.setSelectedIndex((i - 1));
           break;
         }
       }
     }
     this.detach();
     tab.detach();
   }
 }
  /**
   * Adds a doorhanger.
   *
   * <p>This method must be called on the UI thread.
   */
  void addDoorHanger(
      final int tabId,
      final String value,
      final String message,
      final JSONArray buttons,
      final JSONObject options) {
    // Don't add a doorhanger for a tab that doesn't exist
    if (Tabs.getInstance().getTab(tabId) == null) {
      return;
    }

    // Replace the doorhanger if it already exists
    DoorHanger oldDoorHanger = getDoorHanger(tabId, value);
    if (oldDoorHanger != null) {
      removeDoorHanger(oldDoorHanger);
    }

    if (!mInflated) {
      init();
    }

    final DoorHanger newDoorHanger = new DoorHanger(mActivity, tabId, value);
    newDoorHanger.setMessage(message);
    newDoorHanger.setOptions(options);

    for (int i = 0; i < buttons.length(); i++) {
      try {
        JSONObject buttonObject = buttons.getJSONObject(i);
        String label = buttonObject.getString("label");
        String tag = String.valueOf(buttonObject.getInt("callback"));
        newDoorHanger.addButton(label, tag, this);
      } catch (JSONException e) {
        Log.e(LOGTAG, "Error creating doorhanger button", e);
      }
    }

    mDoorHangers.add(newDoorHanger);
    mContent.addView(newDoorHanger);

    // Only update the popup if we're adding a notifcation to the selected tab
    if (tabId == Tabs.getInstance().getSelectedTab().getId()) updatePopup();
  }
 public void setProgressVisibility(boolean visible) {
   if (visible) {
     mFavicon.setImageDrawable(mProgressSpinner);
     mProgressSpinner.start();
     setStopVisibility(true);
   } else {
     mProgressSpinner.stop();
     setStopVisibility(false);
     setFavicon(Tabs.getInstance().getSelectedTab().getFavicon());
   }
 }
 public void onTabChanged(Tab tab, Tabs.TabEvents msg, Object data) {
   switch (msg) {
     case TITLE:
       // if (sameDocument)
       if (Tabs.getInstance().isSelectedTab(tab)) {
         setTitle(tab.getDisplayTitle());
       }
       break;
     case START:
       if (Tabs.getInstance().isSelectedTab(tab)) {
         setSecurityMode(tab.getSecurityMode());
         setReaderVisibility(tab.getReaderEnabled());
         updateBackButton(tab.canDoBack());
         updateForwardButton(tab.canDoForward());
         Boolean showProgress = (Boolean) data;
         if (showProgress && tab.getState() == Tab.STATE_LOADING) setProgressVisibility(true);
       }
       break;
     case STOP:
       if (Tabs.getInstance().isSelectedTab(tab)) {
         updateBackButton(tab.canDoBack());
         updateForwardButton(tab.canDoForward());
         setProgressVisibility(false);
       }
       break;
     case RESTORED:
     case SELECTED:
     case LOCATION_CHANGE:
     case LOAD_ERROR:
       if (Tabs.getInstance().isSelectedTab(tab)) {
         refresh();
       }
       break;
     case CLOSED:
     case ADDED:
       updateTabCountAndAnimate(Tabs.getInstance().getCount());
       updateBackButton(false);
       updateForwardButton(false);
       break;
   }
 }
Exemple #25
0
  /**
   * Updates the popup state.
   *
   * <p>This method must be called on the UI thread.
   */
  void updatePopup() {
    // Bail if the selected tab is null, if there are no active doorhangers,
    // or if we haven't inflated the layout yet (this can happen if updatePopup()
    // is called before the runnable from addDoorHanger() runs).
    Tab tab = Tabs.getInstance().getSelectedTab();
    if (tab == null || mDoorHangers.size() == 0 || !mInflated) {
      dismiss();
      return;
    }

    // Show doorhangers for the selected tab
    int tabId = tab.getId();
    boolean shouldShowPopup = false;
    for (DoorHanger dh : mDoorHangers) {
      if (dh.getTabId() == tabId) {
        dh.setVisibility(View.VISIBLE);
        shouldShowPopup = true;
      } else {
        dh.setVisibility(View.GONE);
      }
    }

    // Dismiss the popup if there are no doorhangers to show for this tab
    if (!shouldShowPopup) {
      dismiss();
      return;
    }

    fixBackgroundForFirst();
    if (isShowing()) {
      update();
      return;
    }

    // If there's no anchor, just show the popup at the top of the gecko app view.
    if (mAnchor == null) {
      showAtLocation(mActivity.getView(), Gravity.TOP, 0, 0);
      return;
    }

    // On tablets, we need to position the popup so that the center of the arrow points to the
    // center of the anchor view. On phones the popup stretches across the entire screen, so the
    // arrow position is determined by its left margin.
    int offset =
        mActivity.isTablet()
            ? mAnchor.getWidth() / 2
                - mArrowWidth / 2
                - ((RelativeLayout.LayoutParams) mArrow.getLayoutParams()).leftMargin
            : 0;
    showAsDropDown(mAnchor, offset, 0);
    // Make the popup focusable for keyboard accessibility.
    setFocusable(true);
  }
  @Override
  void handlePageShow(final int tabId) {
    super.handlePageShow(tabId);
    final Tab tab = Tabs.getInstance().getTab(tabId);
    if (tab == null) return;

    mMainHandler.post(
        new Runnable() {
          public void run() {
            loadFavicon(tab);
          }
        });
  }
  public void setTitle(CharSequence title) {
    Tab tab = Tabs.getInstance().getSelectedTab();

    // We use about:empty as a placeholder for an external page load and
    // we don't want to change the title
    if (tab != null && "about:empty".equals(tab.getURL())) return;

    // Setting a null title for about:home will ensure we just see
    // the "Enter Search or Address" placeholder text
    if (tab != null && "about:home".equals(tab.getURL())) title = null;

    mAwesomeBar.setText(title);
  }
  void handleReaderEnabled(final int tabId) {
    super.handleReaderEnabled(tabId);
    final Tab tab = Tabs.getInstance().getTab(tabId);
    if (tab == null) return;

    mMainHandler.post(
        new Runnable() {
          public void run() {
            if (Tabs.getInstance().isSelectedTab(tab))
              mBrowserToolbar.setReaderMode(tab.getReaderEnabled());
          }
        });
  }
Exemple #29
0
  DoorHangerPopup(GeckoApp aActivity, View aAnchor) {
    super(aActivity);
    mActivity = aActivity;
    mAnchor = aAnchor;

    mInflated = false;
    mArrowWidth = aActivity.getResources().getDimensionPixelSize(R.dimen.doorhanger_arrow_width);
    mDoorHangers = new HashSet<DoorHanger>();

    registerEventListener("Doorhanger:Add");
    registerEventListener("Doorhanger:Remove");
    Tabs.registerOnTabsChangedListener(this);
  }
 public void setProgressVisibility(boolean visible) {
   if (visible) {
     mFavicon.setImageDrawable(mProgressSpinner);
     mProgressSpinner.start();
     setStopVisibility(true);
     Log.i(LOGTAG, "zerdatime " + SystemClock.uptimeMillis() + " - Throbber start");
   } else {
     mProgressSpinner.stop();
     setStopVisibility(false);
     Tab selectedTab = Tabs.getInstance().getSelectedTab();
     if (selectedTab != null) setFavicon(selectedTab.getFavicon());
     Log.i(LOGTAG, "zerdatime " + SystemClock.uptimeMillis() + " - Throbber stop");
   }
 }