Esempio n. 1
0
  /** Restore default search engines in Gecko and retrigger a search engine refresh. */
  protected void restoreDefaultSearchEngines() {
    GeckoAppShell.sendEventToGecko(
        GeckoEvent.createBroadcastEvent("SearchEngines:RestoreDefaults", null));

    // Send message to Gecko to get engines. SearchPreferenceCategory listens for the response.
    GeckoAppShell.sendEventToGecko(
        GeckoEvent.createBroadcastEvent("SearchEngines:GetVisible", null));
  }
  /* Informs Gecko that the screen size has changed. */
  private void sendResizeEventIfNecessary(boolean force) {
    DisplayMetrics metrics = mContext.getResources().getDisplayMetrics();

    IntSize newScreenSize = new IntSize(metrics.widthPixels, metrics.heightPixels);
    IntSize newWindowSize = new IntSize(mView.getWidth(), mView.getHeight());

    boolean screenSizeChanged = !mScreenSize.equals(newScreenSize);
    boolean windowSizeChanged = !mWindowSize.equals(newWindowSize);

    if (!force && !screenSizeChanged && !windowSizeChanged) {
      return;
    }

    mScreenSize = newScreenSize;
    mWindowSize = newWindowSize;

    if (screenSizeChanged) {
      Log.d(LOGTAG, "Screen-size changed to " + mScreenSize);
    }

    if (windowSizeChanged) {
      Log.d(LOGTAG, "Window-size changed to " + mWindowSize);
    }

    GeckoEvent event =
        GeckoEvent.createSizeChangedEvent(
            mWindowSize.width, mWindowSize.height,
            mScreenSize.width, mScreenSize.height);
    GeckoAppShell.sendEventToGecko(event);
    GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Window:Resize", ""));
  }
Esempio n. 3
0
  /*
   * DoorHanger.OnButtonClickListener implementation
   */
  @Override
  public void onButtonClick(DoorHanger dh, String tag) {
    JSONObject response = new JSONObject();
    try {
      response.put("callback", tag);

      CheckBox checkBox = dh.getCheckBox();
      // If the checkbox is being used, pass its value
      if (checkBox != null) {
        response.put("checked", checkBox.isChecked());
      }

      List<PromptInput> doorHangerInputs = dh.getInputs();
      if (doorHangerInputs != null) {
        JSONObject inputs = new JSONObject();
        for (PromptInput input : doorHangerInputs) {
          inputs.put(input.getId(), input.getValue());
        }
        response.put("inputs", inputs);
      }
    } catch (JSONException e) {
      Log.e(LOGTAG, "Error creating onClick response", e);
    }

    GeckoEvent e = GeckoEvent.createBroadcastEvent("Doorhanger:Reply", response.toString());
    GeckoAppShell.sendEventToGecko(e);
    removeDoorHanger(dh);
    updatePopup();
  }
  boolean scrollBy(PointF displacement) {
    if (!mOverridePanning) {
      return false;
    }

    if (!mOverrideScrollAck) {
      mOverrideScrollPending = true;
      mPendingDisplacement.x += displacement.x;
      mPendingDisplacement.y += displacement.y;
      return true;
    }

    JSONObject json = new JSONObject();
    try {
      json.put("x", displacement.x);
      json.put("y", displacement.y);
    } catch (JSONException e) {
      Log.e(LOGTAG, "Error forming subwindow scroll message: ", e);
    }
    GeckoAppShell.sendEventToGecko(
        GeckoEvent.createBroadcastEvent(MESSAGE_SCROLL, json.toString()));

    mOverrideScrollAck = false;
    mOverrideScrollPending = false;
    // clear the |mPendingDisplacement| after serializing |displacement| to
    // JSON because they might be the same object
    mPendingDisplacement.x = 0;
    mPendingDisplacement.y = 0;

    return true;
  }
Esempio n. 5
0
  public AllPagesTab(Context context) {
    super(context);
    mSearchEngines = new ArrayList<SearchEngine>();

    registerEventListener("SearchEngines:Data");
    GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("SearchEngines:Get", null));

    mHandler = new AllPagesHandler();
  }
Esempio n. 6
0
 @Override
 public void onClick(View v) {
   switch (v.getId()) {
     case R.id.find_prev:
       GeckoAppShell.sendEventToGecko(
           GeckoEvent.createBroadcastEvent("FindInPage:Prev", mFindText.getText().toString()));
       getInputMethodManager(mFindText).hideSoftInputFromWindow(mFindText.getWindowToken(), 0);
       break;
     case R.id.find_next:
       GeckoAppShell.sendEventToGecko(
           GeckoEvent.createBroadcastEvent("FindInPage:Next", mFindText.getText().toString()));
       getInputMethodManager(mFindText).hideSoftInputFromWindow(mFindText.getWindowToken(), 0);
       break;
     case R.id.find_close:
       hide();
       break;
   }
 }
Esempio n. 7
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));
 }
Esempio n. 8
0
 /**
  * Handle a confirmation response from the user.
  *
  * @param value String value to return to the browser context.
  */
 public void confirmWithValue(String value) {
   JSONObject result = makeResult(RESULT_OK);
   try {
     result.put("textbox0", value);
   } catch (JSONException ex) {
   }
   GeckoAppShell.sendEventToGecko(
       GeckoEvent.createBroadcastEvent("Prompt:Reply", result.toString()));
 }
Esempio n. 9
0
  public void handleNotificationIntent(Intent i) {
    final Uri data = i.getData();
    if (data == null) {
      Log.e(LOGTAG, "handleNotificationEvent: empty data");
      return;
    }
    final String id = data.getQueryParameter(ID_ATTR);
    final String notificationType = data.getQueryParameter(EVENT_TYPE_ATTR);
    if (id == null || notificationType == null) {
      Log.e(LOGTAG, "handleNotificationEvent: invalid intent parameters");
      return;
    }

    // In case the user swiped out the notification, we empty the id set.
    if (CLEARED_EVENT.equals(notificationType)) {
      mClearableNotifications.remove(id);
      // If Gecko isn't running, we throw away events where the notification was cancelled.
      // i.e. Don't bug the user if they're just closing a bunch of notifications.
      if (!GeckoThread.checkLaunchState(GeckoThread.LaunchState.GeckoRunning)) {
        return;
      }
    }

    JSONObject args = new JSONObject();

    // The handler and cookie parameters are optional
    final String handler = data.getQueryParameter(HANDLER_ATTR);
    final String cookie = i.getStringExtra(COOKIE_ATTR);

    try {
      args.put(ID_ATTR, id);
      args.put(EVENT_TYPE_ATTR, notificationType);
      args.put(HANDLER_ATTR, handler);
      args.put(COOKIE_ATTR, cookie);

      if (BUTTON_EVENT.equals(notificationType)) {
        final String actionName = data.getQueryParameter(ACTION_ID_ATTR);
        args.put(ACTION_ID_ATTR, actionName);
      }

      Log.i(LOGTAG, "Send " + args.toString());
      GeckoAppShell.sendEventToGecko(
          GeckoEvent.createBroadcastEvent("Notification:Event", args.toString()));
    } catch (JSONException e) {
      Log.e(LOGTAG, "Error building JSON notification arguments.", e);
    }

    // If the notification was clicked, we are closing it. This must be executed after
    // sending the event to js side because when the notification is canceled no event can be
    // handled.
    if (CLICK_EVENT.equals(notificationType) && !i.getBooleanExtra(ONGOING_ATTR, false)) {
      hideNotification(id, handler, cookie);
    }
  }
Esempio n. 10
0
 /**
  * Load a URL resource into the Browser.
  *
  * @param url The URL string.
  */
 public void loadUrl(String url) {
   JSONObject args = new JSONObject();
   try {
     args.put("url", url);
     args.put("parentId", -1);
     args.put("newTab", false);
     args.put("tabID", mId);
   } catch (Exception e) {
     Log.w(LOGTAG, "Error building JSON arguments for loadUrl.", e);
   }
   GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Tab:Load", args.toString()));
 }
Esempio n. 11
0
 @Override
 public boolean onActionItemClicked(ActionModeCompat mode, MenuItem item) {
   try {
     final JSONObject obj = mItems.getJSONObject(item.getItemId());
     GeckoAppShell.sendEventToGecko(
         GeckoEvent.createBroadcastEvent("TextSelection:Action", obj.optString("id")));
     return true;
   } catch (Exception ex) {
     Log.i(LOGTAG, "Exception calling action", ex);
   }
   return false;
 }
Esempio n. 12
0
 private void sendNotificationWasClosed(String id, String handlerKey, String cookie) {
   final JSONObject args = new JSONObject();
   try {
     args.put(ID_ATTR, id);
     args.put(HANDLER_ATTR, handlerKey);
     args.put(COOKIE_ATTR, cookie);
     args.put(EVENT_TYPE_ATTR, CLOSED_EVENT);
     Log.i(LOGTAG, "Send " + args.toString());
     GeckoAppShell.sendEventToGecko(
         GeckoEvent.createBroadcastEvent("Notification:Event", args.toString()));
   } catch (JSONException ex) {
     Log.e(LOGTAG, "sendNotificationWasClosed: error building JSON notification arguments.", ex);
   }
 }
Esempio n. 13
0
    @Override
    public void onRefresh() {
      final JSONObject response = new JSONObject();
      try {
        response.put(JSON_KEY_PANEL_ID, panelId);
        response.put(JSON_KEY_VIEW_INDEX, viewIndex);
      } catch (JSONException e) {
        Log.e(LOGTAG, "Could not create refresh message", e);
        return;
      }

      final GeckoEvent event =
          GeckoEvent.createBroadcastEvent("HomePanels:RefreshView", response.toString());
      GeckoAppShell.sendEventToGecko(event);
    }
  private void sendPointToGecko(String event, MotionEvent motionEvent) {
    String json;
    try {
      PointF point = new PointF(motionEvent.getX(), motionEvent.getY());
      point = mTarget.convertViewPointToLayerPoint(point);
      if (point == null) {
        return;
      }
      json = PointUtils.toJSON(point).toString();
    } catch (Exception e) {
      Log.e(LOGTAG, "Unable to convert point to JSON for " + event, e);
      return;
    }

    GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent(event, json));
  }
  // send the Preferences:Set message to Gecko
  public static void setPreference(String pref, Object value) {
    if (pref == null || pref.length() == 0) return;

    try {
      JSONObject jsonPref = new JSONObject();
      jsonPref.put("name", pref);
      if (value instanceof Boolean) {
        jsonPref.put("type", "bool");
        jsonPref.put("value", ((Boolean) value).booleanValue());
      } else if (value instanceof Integer) {
        jsonPref.put("type", "int");
        jsonPref.put("value", ((Integer) value).intValue());
      } else {
        jsonPref.put("type", "string");
        jsonPref.put("value", String.valueOf(value));
      }

      GeckoEvent event = GeckoEvent.createBroadcastEvent("Preferences:Set", jsonPref.toString());
      GeckoAppShell.sendEventToGecko(event);
    } catch (JSONException e) {
      Log.e(LOGTAG, "JSON exception: ", e);
    }
  }
Esempio n. 16
0
 public static void onLayerViewFocusChanged(LayerView layerview, boolean gainFocus) {
   if (sEnabled)
     GeckoAppShell.sendEventToGecko(
         GeckoEvent.createBroadcastEvent("Accessibility:Focus", gainFocus ? "true" : "false"));
 }
  // Initialize preferences by sending the "Preferences:Get" command to Gecko
  private void initValues() {
    JSONArray jsonPrefs = new JSONArray(mPreferencesList);

    GeckoEvent event = GeckoEvent.createBroadcastEvent("Preferences:Get", jsonPrefs.toString());
    GeckoAppShell.sendEventToGecko(event);
  }
Esempio n. 18
0
 @Override
 public void afterTextChanged(Editable s) {
   GeckoAppShell.sendEventToGecko(
       GeckoEvent.createBroadcastEvent("FindInPage:Find", s.toString()));
 }
Esempio n. 19
0
 public void hide() {
   setVisibility(GONE);
   getInputMethodManager(mFindText).hideSoftInputFromWindow(mFindText.getWindowToken(), 0);
   GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("FindInPage:Closed", null));
 }
Esempio n. 20
0
 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
   Tab tab = null;
   Intent intent = null;
   switch (item.getItemId()) {
     case R.id.bookmark:
       tab = Tabs.getInstance().getSelectedTab();
       if (tab != null) {
         if (item.isChecked()) {
           tab.removeBookmark();
           Toast.makeText(this, R.string.bookmark_removed, Toast.LENGTH_SHORT).show();
           item.setIcon(R.drawable.ic_menu_bookmark_add);
         } else {
           tab.addBookmark();
           Toast.makeText(this, R.string.bookmark_added, Toast.LENGTH_SHORT).show();
           item.setIcon(R.drawable.ic_menu_bookmark_remove);
         }
       }
       return true;
     case R.id.share:
       shareCurrentUrl();
       return true;
     case R.id.reload:
       tab = Tabs.getInstance().getSelectedTab();
       if (tab != null) tab.doReload();
       return true;
     case R.id.forward:
       tab = Tabs.getInstance().getSelectedTab();
       if (tab != null) tab.doForward();
       return true;
     case R.id.save_as_pdf:
       GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("SaveAs:PDF", null));
       return true;
     case R.id.settings:
       intent = new Intent(this, GeckoPreferences.class);
       startActivity(intent);
       return true;
     case R.id.addons:
       Tabs.getInstance().loadUrlInTab("about:addons");
       return true;
     case R.id.downloads:
       Tabs.getInstance().loadUrlInTab("about:downloads");
       return true;
     case R.id.apps:
       Tabs.getInstance().loadUrlInTab("about:apps");
       return true;
     case R.id.char_encoding:
       GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("CharEncoding:Get", null));
       return true;
     case R.id.find_in_page:
       mFindInPageBar.show();
       return true;
     case R.id.desktop_mode:
       Tab selectedTab = Tabs.getInstance().getSelectedTab();
       if (selectedTab == null) return true;
       JSONObject args = new JSONObject();
       try {
         args.put("desktopMode", !item.isChecked());
         args.put("tabId", selectedTab.getId());
       } catch (JSONException e) {
         Log.e(LOGTAG, "error building json arguments");
       }
       GeckoAppShell.sendEventToGecko(
           GeckoEvent.createBroadcastEvent("DesktopMode:Change", args.toString()));
       return true;
     case R.id.new_tab:
       addTab();
       return true;
     case R.id.new_private_tab:
       Tabs.getInstance().loadUrl("about:home", Tabs.LOADURL_NEW_TAB | Tabs.LOADURL_PRIVATE);
       return true;
     default:
       return super.onOptionsItemSelected(item);
   }
 }
 private void cancelTouch() {
   GeckoEvent e = GeckoEvent.createBroadcastEvent("Gesture:CancelTouch", "");
   GeckoAppShell.sendEventToGecko(e);
 }
Esempio n. 22
0
 // Called when the user exits the action mode
 @Override
 public void onDestroyActionMode(ActionModeCompat mode) {
   mActionMode = null;
   mCallback = null;
   GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("TextSelection:End", null));
 }
Esempio n. 23
0
 /** Handle a cancellation response from the user. */
 public void cancel() {
   JSONObject result = makeResult(RESULT_CANCEL);
   GeckoAppShell.sendEventToGecko(
       GeckoEvent.createBroadcastEvent("Prompt:Reply", result.toString()));
 }
Esempio n. 24
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Log.d(LOGTAG, "creating awesomebar");

    mResolver = Tabs.getInstance().getContentResolver();
    LayoutInflater.from(this).setFactory(GeckoViewsFactory.getInstance());

    setContentView(R.layout.awesomebar);

    mGoButton = (ImageButton) findViewById(R.id.awesomebar_button);
    mText = (AwesomeBarEditText) findViewById(R.id.awesomebar_text);

    TabWidget tabWidget = (TabWidget) findViewById(android.R.id.tabs);
    tabWidget.setDividerDrawable(null);

    mAwesomeTabs = (AwesomeBarTabs) findViewById(R.id.awesomebar_tabs);
    mAwesomeTabs.setOnUrlOpenListener(
        new AwesomeBarTabs.OnUrlOpenListener() {
          public void onUrlOpen(String url) {
            openUrlAndFinish(url);
          }

          public void onSearch(String engine, String text) {
            openSearchAndFinish(text, engine);
          }

          public void onEditSuggestion(final String text) {
            GeckoApp.mAppContext.mMainHandler.post(
                new Runnable() {
                  public void run() {
                    mText.setText(text);
                    mText.setSelection(mText.getText().length());
                    mText.requestFocus();
                    InputMethodManager imm =
                        (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                    imm.showSoftInput(mText, InputMethodManager.SHOW_IMPLICIT);
                  }
                });
          }
        });

    mGoButton.setOnClickListener(
        new Button.OnClickListener() {
          public void onClick(View v) {
            openUserEnteredAndFinish(mText.getText().toString());
          }
        });

    Intent intent = getIntent();
    String currentUrl = intent.getStringExtra(CURRENT_URL_KEY);
    mTarget = intent.getStringExtra(TARGET_KEY);
    if (currentUrl != null) {
      mText.setText(currentUrl);
      mText.selectAll();
    }

    mText.setOnKeyPreImeListener(
        new AwesomeBarEditText.OnKeyPreImeListener() {
          public boolean onKeyPreIme(View v, int keyCode, KeyEvent event) {
            // We only want to process one event per tap
            if (event.getAction() != KeyEvent.ACTION_DOWN) return false;

            if (keyCode == KeyEvent.KEYCODE_ENTER) {
              // If the AwesomeBar has a composition string, don't submit the text yet.
              // ENTER is needed to commit the composition string.
              Editable content = mText.getText();
              if (!hasCompositionString(content)) {
                openUserEnteredAndFinish(content.toString());
                return true;
              }
            }

            // If input method is in fullscreen mode, we want to dismiss
            // it instead of closing awesomebar straight away.
            InputMethodManager imm =
                (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            if (keyCode == KeyEvent.KEYCODE_BACK && !imm.isFullscreenMode()) {
              // Let mAwesomeTabs try to handle the back press, since we may be in a
              // bookmarks sub-folder.
              if (mAwesomeTabs.onBackPressed()) return true;

              // If mAwesomeTabs.onBackPressed() returned false, we didn't move up
              // a folder level, so just exit the activity.
              cancelAndFinish();
              return true;
            }

            return false;
          }
        });

    mText.addTextChangedListener(
        new TextWatcher() {
          public void afterTextChanged(Editable s) {
            String text = s.toString();
            mAwesomeTabs.filter(text);

            // If the AwesomeBar has a composition string, don't call updateGoButton().
            // That method resets IME and composition state will be broken.
            if (!hasCompositionString(s)) {
              updateGoButton(text);
            }

            // cancel previous query
            if (mSuggestTask != null) {
              mSuggestTask.cancel(true);
            }

            if (mSuggestClient != null) {
              mSuggestTask =
                  new AsyncTask<String, Void, ArrayList<String>>() {
                    protected ArrayList<String> doInBackground(String... query) {
                      return mSuggestClient.query(query[0]);
                    }

                    protected void onPostExecute(ArrayList<String> suggestions) {
                      mAwesomeTabs.setSuggestions(suggestions);
                    }
                  };
              mSuggestTask.execute(text);
            }
          }

          public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            // do nothing
          }

          public void onTextChanged(CharSequence s, int start, int before, int count) {
            // do nothing
          }
        });

    mText.setOnKeyListener(
        new View.OnKeyListener() {
          public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_ENTER) {
              if (event.getAction() != KeyEvent.ACTION_DOWN) return true;

              openUserEnteredAndFinish(mText.getText().toString());
              return true;
            } else {
              return false;
            }
          }
        });

    registerForContextMenu(mAwesomeTabs.findViewById(R.id.all_pages_list));
    registerForContextMenu(mAwesomeTabs.findViewById(R.id.bookmarks_list));
    registerForContextMenu(mAwesomeTabs.findViewById(R.id.history_list));

    GeckoAppShell.registerGeckoEventListener("SearchEngines:Data", this);
    GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("SearchEngines:Get", null));
  }