/* (non-Javadoc)
   * @see org.appcelerator.titanium.module.ITitaniumHttpClient#open(java.lang.String, java.lang.String)
   */
  public void open(String method, String url) throws MethodNotSupportedException {
    if (DBG) {
      Log.d(LCAT, "open request method=" + method + " url=" + url);
    }
    TitaniumWebView wv = softWebView.get();
    if (wv != null) {
      me.syncId = wv.registerLock();
    }

    request = new DefaultHttpRequestFactory().newHttpRequest(method, url);
    Uri uri = Uri.parse(url);
    host = new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme());
    if (uri.getUserInfo() != null) {
      credentials = new UsernamePasswordCredentials(uri.getUserInfo());
    }
    setReadyState(READY_STATE_LOADING, syncId);
    setRequestHeader("User-Agent", userAgent);
    setRequestHeader("X-Requested-With", "XMLHttpRequest");
  }
Пример #2
0
  public void open(String method, String url) {
    if (DBG) {
      Log.d(LCAT, "open request method=" + method + " url=" + url);
    }

    this.method = method;

    String cleanUrl = url;
    if (url.startsWith("http")) {
      int beginQ = url.indexOf('?');
      if (beginQ > 7 && url.length() > beginQ) {
        String left = url.substring(0, beginQ);
        String right = url.substring(beginQ + 1);
        // first decoding below, in case it's partially encoded already.
        cleanUrl = Uri.encode(Uri.decode(left), ":/") + "?" + Uri.encode(Uri.decode(right), "&=#");
      } else {
        cleanUrl = Uri.encode(Uri.decode(url), ":/#");
      }
    }

    uri = Uri.parse(cleanUrl);

    host = new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme());
    if (uri.getUserInfo() != null) {
      credentials = new UsernamePasswordCredentials(uri.getUserInfo());
    }
    setReadyState(READY_STATE_OPENED);
    setRequestHeader("User-Agent", (String) proxy.getDynamicValue("userAgent"));
    // Causes Auth to Fail with twitter and other size apparently block X- as well
    // Ticket #729, ignore twitter for now
    if (!uri.getHost().contains("twitter.com")) {
      setRequestHeader("X-Requested-With", "XMLHttpRequest");
    } else {
      Log.i(LCAT, "Twitter: not sending X-Requested-With header");
    }
  }
Пример #3
0
  /** @return a uri which can be used for logging (i.e. with credentials masked) */
  public String getStoreUriForLogging() {
    Uri uri = Uri.parse(this.uri);
    String userInfo = uri.getUserInfo();

    if (!TextUtils.isEmpty(userInfo) && userInfo.contains(":")) {
      String[] parts = userInfo.split(":", 2);
      userInfo = parts[0] + ":" + (parts[1].replaceAll(".", "X"));
      String host = uri.getHost();
      if (uri.getPort() != -1) {
        host += ":" + uri.getPort();
      }
      return uri.buildUpon().encodedAuthority(userInfo + "@" + host).toString();
    } else {
      return uri.toString();
    }
  }
Пример #4
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.view_bookmark);

    setTitle(R.string.view_bookmark_title);

    Intent intent = getIntent();

    if (Intent.ACTION_VIEW.equals(intent.getAction())) {

      Uri data = intent.getData();

      if (data != null) {
        path = data.getPath();
        username = data.getUserInfo();

      } else username = mAccount.name;

      bookmark = new Bookmark();

      if (path.contains("/bookmarks")) {
        if (isMyself()) {
          int id = Integer.parseInt(data.getLastPathSegment());
          bookmark.setId(id);
        } else {
          bookmark.setDescription(data.getQueryParameter("title"));
          bookmark.setUrl(data.getQueryParameter("url"));
          bookmark.setNotes(data.getQueryParameter("notes"));
          bookmark.setTime(Long.parseLong(data.getQueryParameter("time")));
          if (!data.getQueryParameter("tags").equals("null"))
            bookmark.setTagString(data.getQueryParameter("tags"));
          bookmark.setAccount(data.getQueryParameter("account"));
        }
      }

      BookmarkViewType type =
          (BookmarkViewType) intent.getSerializableExtra("com.pindroid.BookmarkViewType");
      if (type == null) type = BookmarkViewType.VIEW;

      ViewBookmarkFragment frag =
          (ViewBookmarkFragment)
              getSupportFragmentManager().findFragmentById(R.id.view_bookmark_fragment);
      frag.setBookmark(bookmark, type);
    }
  }
Пример #5
0
  /**
   * Returns true if the user has disabled sharing their location with url (e.g. via the geolocation
   * infobar). If the user has not chosen a preference for url and url uses the https scheme, this
   * considers the user's preference for url with the http scheme instead.
   */
  public static boolean isLocationDisabledForUrl(Uri uri) {
    // TODO(finnur): Delete this method once GeolocationHeader has been upstreamed.
    GeolocationInfo locationSettings = new GeolocationInfo(uri.toString(), null);
    ContentSetting locationPermission = locationSettings.getContentSetting();

    // If no preference has been chosen and the scheme is https, fall back to the preference for
    // this same host over http with no explicit port number.
    if (locationPermission == null || locationPermission == ContentSetting.ASK) {
      String scheme = uri.getScheme();
      if (scheme != null
          && scheme.toLowerCase(Locale.US).equals("https")
          && uri.getAuthority() != null
          && uri.getUserInfo() == null) {
        String urlWithHttp = "http://" + uri.getHost();
        locationSettings = new GeolocationInfo(urlWithHttp, null);
        locationPermission = locationSettings.getContentSetting();
      }
    }

    return locationPermission == ContentSetting.BLOCK;
  }
Пример #6
0
  public static ShadowsocksConfig parse(String proxyInfo) throws Exception {
    ShadowsocksConfig config = new ShadowsocksConfig();
    Uri uri = Uri.parse(proxyInfo);
    if (uri.getPort() == -1) {
      String base64String = uri.getHost();
      proxyInfo =
          "ss://" + new String(Base64.decode(base64String.getBytes("ASCII"), Base64.DEFAULT));
      uri = Uri.parse(proxyInfo);
    }

    String userInfoString = uri.getUserInfo();
    if (userInfoString != null) {
      String[] userStrings = userInfoString.split(":");
      config.EncryptMethod = userStrings[0];
      if (userStrings.length >= 2) {
        config.Password = userStrings[1];
      }
    }
    config.ServerAddress = new InetSocketAddress(uri.getHost(), uri.getPort());
    config.Encryptor = EncryptorFactory.createEncryptorByConfig(config);
    return config;
  }
Пример #7
0
  String getAdditionInfo(String url) {
    String s = "";
    if (url.contains("bongda")) {
      try {
        HtmlCleaner cleaner = new HtmlCleaner();
        String id = url.substring(url.lastIndexOf("/"));
        id = id.substring(1, id.indexOf("."));
        Uri ss = Uri.parse("http://m.bongdaplus.vn/Story.aspx?sid=" + id);

        URI fine =
            new URI(
                ss.getScheme(),
                ss.getUserInfo(),
                ss.getHost(),
                ss.getPort(),
                ss.getPath(),
                ss.getQuery(),
                ss.getFragment());
        HttpClient httpclient = new DefaultHttpClient();
        httpclient.getParams().setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.BEST_MATCH);
        HttpGet httpget = new HttpGet(fine);
        httpget.addHeader(
            "user-agent", "Mozilla/5.0 (Linux; U; Android 2.3.3) Gecko/20100101 Firefox/8.0");
        httpget.addHeader("accept-language", "en-us,en;q=0.5");
        HttpResponse response = httpclient.execute(httpget);
        InputStream binaryreader = new BufferedInputStream(response.getEntity().getContent());
        BufferedReader buf = new BufferedReader(new InputStreamReader(binaryreader));
        String sss;
        StringBuilder sb = new StringBuilder();
        while ((sss = buf.readLine()) != null) {
          sb.append(sss);
        }

        //	    		URL u = new URL(ss.getScheme(), ss.getHost(), ss.getPort(), ss.getPath());
        TagNode root = cleaner.clean(sb.toString());
        TagNode div = root.findElementByAttValue("class", "story-body", true, false);
        TagNode[] child = div.getElementsByName("strong", true);
        for (int i = 0; i < child.length; i++) child[i].removeFromTree();
        child = div.getElementsByAttValue("class", "listing", true, false);
        for (int i = 0; i < child.length; i++) child[i].removeFromTree();
        child = div.getElementsByName("ul", true);
        for (int i = 0; i < child.length; i++) child[i].removeFromTree();
        child = div.getElementsByName("img", true);
        for (int i = 0; i < child.length; i++)
          child[i].setAttribute("style", "width: 100%; height: auto;");
        s = cleaner.getInnerHtml(div);
        if (s.indexOf("VideoPlaying(") > 0) {
          int x = s.indexOf("VideoPlaying(");
          int st = s.indexOf("'", x);
          int en = s.indexOf("'", st + 1);
          String urlvideo = "http://bongdaplus.vn" + s.substring(st + 1, en);
          s = s + "<a href=\"" + urlvideo + "\"> Video </a></br></br>";
        }
      } catch (Exception e) {
        e.printStackTrace();
      }
    } else if (url.contains("teamtalk")) {
      try {
        HtmlCleaner cleaner = new HtmlCleaner();
        Uri ss = Uri.parse(url);
        URL u = new URL(ss.getScheme(), ss.getHost(), ss.getPort(), ss.getPath());
        TagNode root = cleaner.clean(u);
        TagNode div = root.findElementByAttValue("class", "tt-article-text", true, false);
        TagNode[] child = div.getElementsByName("p", true);
        for (int i = 0; i < child.length; i++)
          if (child[i].hasAttribute("class") || child[i].hasAttribute("style"))
            child[i].removeFromTree();
        child = div.getElementsByName("img", true);
        for (int i = 0; i < child.length; i++)
          child[i].setAttribute("style", "max-width: 80%; height: auto;");
        s = cleaner.getInnerHtml(div);
      } catch (Exception e) {
        e.printStackTrace();
      }
    } else if (url.contains("licheuro")) {
      try {
        HtmlCleaner cleaner = new HtmlCleaner();
        Uri ss = Uri.parse(url);
        URL u = new URL(ss.getScheme(), ss.getHost(), ss.getPort(), ss.getPath());
        TagNode root = cleaner.clean(u);
        TagNode div = root.findElementByAttValue("class", "entry", true, false);

        TagNode[] child = div.getElementsByName("span", true);
        for (int i = 0; i < child.length; i++) child[i].removeFromTree();
        child = div.getElementsByName("strong", true);
        for (int i = 0; i < child.length; i++) {
          child[i].getParent().addChildren(child[i].getChildren());
          child[i].getParent().addChild(child[i].getText());
          child[i].removeFromTree();
        }
        child = div.getElementsByName("h1", true);
        for (int i = 0; i < child.length; i++) {
          child[i].getParent().addChildren(child[i].getChildren());
          child[i].getParent().addChild(child[i].getText());
          child[i].removeFromTree();
        }
        child = div.getElementsByAttValue("class", "boxpost", true, true);
        for (int i = 0; i < child.length; i++) child[i].removeFromTree();
        child = div.getElementsByAttValue("class", "ratingblock ", true, true);
        for (int i = 0; i < child.length; i++) child[i].removeFromTree();
        child = div.getElementsByName("iframe", true);
        for (int i = 0; i < child.length; i++) child[i].removeFromTree();
        child = div.getElementsByName("blockqoute", true);
        for (int i = 0; i < child.length; i++) {
          child[i].getParent().addChildren(child[i].getChildren());
          child[i].removeFromTree();
        }

        child = div.getElementsByAttValue("class", "dd_outer", true, true);
        for (int i = 0; i < child.length; i++) child[i].removeFromTree();
        child = div.getElementsByAttValue("id", "fb-root", true, true);
        for (int i = 0; i < child.length; i++) child[i].removeFromTree();
        child = div.getElementsByAttValue("id", "fbSEOComments", true, true);
        for (int i = 0; i < child.length; i++) child[i].removeFromTree();
        child = div.getElementsByAttValue("id", "ajax_comments_wrapper", true, true);
        for (int i = 0; i < child.length; i++) child[i].removeFromTree();
        child = div.getElementsByName("table", true);
        for (int i = 0; i < child.length; i++) {
          child[i].setAttribute("style", "max-width: 100%; height: auto;");
          child[i].setAttribute("width", "100%");
        }
        child = div.getElementsByName("script", true);
        for (int i = 0; i < child.length; i++) child[i].removeFromTree();
        child = div.getElementsByName("img", true);
        for (int i = 0; i < child.length; i++)
          child[i].setAttribute("style", "max-width: 80%; height: auto;");
        s = cleaner.getInnerHtml(div);
        if (s.indexOf("\"file\":") > 0) {
          int x = s.indexOf("\"file\":");
          int st = s.indexOf("http", x);
          int en = s.indexOf("\"", st + 1);
          String urlvideo = s.substring(st, en);
          s = s + "<a href=\"" + urlvideo + "\"> Video </a></br></br>";
        }
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
    System.out.println(s);
    return s;
  }
Пример #8
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.browse_bookmarks);

    Intent intent = getIntent();

    Uri data = intent.getData();
    FragmentManager fm = getSupportFragmentManager();
    FragmentTransaction t = fm.beginTransaction();

    if (fm.findFragmentById(R.id.listcontent) == null) {
      Fragment bookmarkFrag = new Fragment();

      if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
        Bundle searchData = intent.getBundleExtra(SearchManager.APP_DATA);

        if (searchData != null) {
          tagname = searchData.getString("tagname");
          username = searchData.getString("username");
          unread = searchData.getBoolean("unread");
        }

        String query = intent.getStringExtra(SearchManager.QUERY);

        if (intent.hasExtra("username")) {
          username = intent.getStringExtra("username");
        }

        bookmarkFrag = new BrowseBookmarksFragment();
        ((BrowseBookmarksFragment) bookmarkFrag).setSearchQuery(query, username, tagname, unread);
      } else if (!Constants.ACTION_SEARCH_SUGGESTION.equals(intent.getAction())) {
        if (data != null) {

          if (data.getUserInfo() != "") {
            username = data.getUserInfo();
          } else username = mAccount.name;

          tagname = data.getQueryParameter("tagname");
          unread = data.getQueryParameter("unread") != null;
          path = data.getPath();
        }

        if (isMyself()) {
          bookmarkFrag = new BrowseBookmarksFragment();
          ((BrowseBookmarksFragment) bookmarkFrag).setQuery(username, tagname, unread);
        } else {
          bookmarkFrag = new BrowseBookmarkFeedFragment();
          ((BrowseBookmarkFeedFragment) bookmarkFrag).setQuery(username, tagname);
        }
      }

      t.add(R.id.listcontent, bookmarkFrag);
    }

    BrowseTagsFragment tagFrag = (BrowseTagsFragment) fm.findFragmentById(R.id.tagcontent);
    if (tagFrag != null) {
      tagFrag.setAccount(username);
      tagFrag.setAction("notpick");
    }

    if (path.contains("tags")) {
      t.hide(fm.findFragmentById(R.id.maincontent));
      findViewById(R.id.panel_collapse_button).setVisibility(View.GONE);
    } else {
      if (tagFrag != null) {
        t.hide(tagFrag);
      }
    }

    Fragment addFrag = fm.findFragmentById(R.id.addcontent);
    if (addFrag != null) {
      t.hide(addFrag);
    }

    t.commit();
  }