/**
   * If this looks like a POST request (form submission) containing a username and password, give
   * the user the option of saving them. Will either do nothing, or block until the UI interaction
   * is complete.
   *
   * <p>Called by startLoadingResource when using the Apache HTTP stack. Called directly by WebKit
   * when using the Chrome HTTP stack.
   *
   * @param postData The data about to be sent as the body of a POST request.
   * @param username The username entered by the user (sniffed from the DOM).
   * @param password The password entered by the user (sniffed from the DOM).
   */
  private void maybeSavePassword(byte[] postData, String username, String password) {
    if (postData == null
        || username == null
        || username.isEmpty()
        || password == null
        || password.isEmpty()) {
      return; // No password to save.
    }

    if (!mSettings.getSavePassword()) {
      return; // User doesn't want to save passwords.
    }

    try {
      if (DebugFlags.BROWSER_FRAME) {
        Assert.assertNotNull(mCallbackProxy.getBackForwardList().getCurrentItem());
      }
      WebAddress uri =
          new WebAddress(mCallbackProxy.getBackForwardList().getCurrentItem().getUrl());
      String schemePlusHost = uri.getScheme() + uri.getHost();
      // Check to see if the username & password appear in
      // the post data (there could be another form on the
      // page and that was posted instead.
      String postString = new String(postData);
      if (postString.contains(URLEncoder.encode(username))
          && postString.contains(URLEncoder.encode(password))) {
        String[] saved = mDatabase.getUsernamePassword(schemePlusHost);
        if (saved != null) {
          // null username implies that user has chosen not to
          // save password
          if (saved[0] != null) {
            // non-null username implies that user has
            // chosen to save password, so update the
            // recorded password
            mDatabase.setUsernamePassword(schemePlusHost, username, password);
          }
        } else {
          // CallbackProxy will handle creating the resume
          // message
          mCallbackProxy.onSavePassword(schemePlusHost, username, password, null);
        }
      }
    } catch (ParseException ex) {
      // if it is bad uri, don't save its password
    }
  }
  /**
   * Handle messages posted to us.
   *
   * @param msg The message to handle.
   */
  @Override
  public void handleMessage(Message msg) {
    if (mBlockMessages) {
      return;
    }
    switch (msg.what) {
      case FRAME_COMPLETED:
        {
          if (mSettings.getSavePassword() && hasPasswordField()) {
            WebHistoryItem item = mCallbackProxy.getBackForwardList().getCurrentItem();
            if (item != null) {
              WebAddress uri = new WebAddress(item.getUrl());
              String schemePlusHost = uri.getScheme() + uri.getHost();
              String[] up = mDatabase.getUsernamePassword(schemePlusHost);
              if (up != null && up[0] != null) {
                setUsernamePassword(up[0], up[1]);
              }
            }
          }
          if (!JniUtil.useChromiumHttpStack()) {
            WebViewWorker.getHandler().sendEmptyMessage(WebViewWorker.MSG_TRIM_CACHE);
          }
          break;
        }

      case POLICY_FUNCTION:
        {
          nativeCallPolicyFunction(msg.arg1, msg.arg2);
          break;
        }

      case ORIENTATION_CHANGED:
        {
          if (mOrientation != msg.arg1) {
            mOrientation = msg.arg1;
            nativeOrientationChanged(msg.arg1);
          }
          break;
        }

      default:
        break;
    }
  }
Beispiel #3
0
  /** Create an action from common {@link Data} elements. */
  public DataAction(Context context, DataItem item) {
    mContext = context;
    mKind = item.getDataKind();
    mMimeType = item.getMimeType();

    /*
     * New Feature by Mediatek Begin.
     *   Original Android's code:
     *
     *   CR ID: ALPS00308657
     *   Descriptions: RCS
     */
    String exMimeType = null;
    boolean pluginStatus =
        ExtensionManager.getInstance()
            .getContactDetailExtension()
            .checkPluginSupport(ExtensionManager.COMMD_FOR_RCS);
    if (pluginStatus) {
      exMimeType =
          ExtensionManager.getInstance()
              .getContactDetailExtension()
              .getExtentionMimeType(ExtensionManager.COMMD_FOR_RCS);
    }
    /*
     * New Feature by Mediatek End.
     */

    // Determine type for subtitle
    mSubtitle = "";
    if (item.hasKindTypeColumn()) {
      final int typeValue = item.getKindTypeColumn();
      // get type string
      /** M:AAS @ { */
      if (SimUtils.isAasPhoneType(typeValue)) {
        int slotId =
            ExtensionManager.getInstance()
                .getContactAccountExtension()
                .getCurrentSlot(ExtensionManager.COMMD_FOR_AAS);
        mSubtitle =
            (String)
                ExtensionManager.getInstance()
                    .getContactAccountExtension()
                    .getTypeLabel(
                        context.getResources(),
                        typeValue,
                        item.getContentValues().getAsString(Data.DATA3),
                        slotId,
                        ExtensionManager.COMMD_FOR_AAS);
      } else {
        /** M: @ } */
        for (EditType type : item.getDataKind().typeList) {
          if (type.rawValue == typeValue) {
            if (type.customColumn == null) {
              // Non-custom type. Get its description from the
              // resource
              mSubtitle = context.getString(type.labelRes);
            } else {
              // Custom type. Read it from the database
              mSubtitle = item.getContentValues().getAsString(type.customColumn);
            }
            break;
          }
        }
      }
    }

    mIsPrimary = item.isSuperPrimary();
    mBody = item.buildDataStringForDisplay();

    mDataId = item.getId();
    mDataUri = ContentUris.withAppendedId(Data.CONTENT_URI, mDataId);

    final boolean hasPhone = PhoneCapabilityTester.isPhone(mContext);
    final boolean hasSms = PhoneCapabilityTester.isSmsIntentRegistered(mContext);

    // Handle well-known MIME-types with special care
    if (item instanceof PhoneDataItem) {
      if (PhoneCapabilityTester.isPhone(mContext)) {
        PhoneDataItem phone = (PhoneDataItem) item;
        final String number = phone.getNumber();
        if (!TextUtils.isEmpty(number)) {

          /*
           * New Feature by Mediatek Begin.
           *   Original Android's code:
           *
           *   CR ID: ALPS00308657
           *   Descriptions: RCS
           */
          mPhoneAndSubtitle.put(number, mSubtitle.toString());
          /*
           * New Feature by Mediatek End.
           */

          final Intent phoneIntent = hasPhone ? ContactsUtils.getCallIntent(number) : null;
          final Intent smsIntent =
              hasSms
                  ? new Intent(
                      Intent.ACTION_SENDTO, Uri.fromParts(Constants.SCHEME_SMSTO, number, null))
                  : null;

          // Configure Icons and Intents. Notice actionIcon is already set to the phone
          if (hasPhone && hasSms) {
            mIntent = phoneIntent;
            mAlternateIntent = smsIntent;
            mAlternateIconRes = item.getDataKind().iconAltRes;
            mAlternateIconDescriptionRes = item.getDataKind().iconAltDescriptionRes;
          } else if (hasPhone) {
            mIntent = phoneIntent;
          } else if (hasSms) {
            mIntent = smsIntent;
          }
        }
      }
    } else if (item instanceof SipAddressDataItem) {
      if (PhoneCapabilityTester.isSipPhone(mContext)) {
        final SipAddressDataItem sip = (SipAddressDataItem) item;
        final String address = sip.getSipAddress();
        if (!TextUtils.isEmpty(address)) {
          final Uri callUri = Uri.fromParts(Constants.SCHEME_SIP, address, null);
          mIntent = ContactsUtils.getCallIntent(callUri);
          // Note that this item will get a SIP-specific variant
          // of the "call phone" icon, rather than the standard
          // app icon for the Phone app (which we show for
          // regular phone numbers.)  That's because the phone
          // app explicitly specifies an android:icon attribute
          // for the SIP-related intent-filters in its manifest.
        }
      }
    } else if (item instanceof EmailDataItem) {
      final EmailDataItem email = (EmailDataItem) item;
      final String address = email.getData();
      if (!TextUtils.isEmpty(address)) {
        final Uri mailUri = Uri.fromParts(Constants.SCHEME_MAILTO, address, null);
        mIntent = new Intent(Intent.ACTION_SENDTO, mailUri);
      }

    } else if (item instanceof WebsiteDataItem) {
      final WebsiteDataItem website = (WebsiteDataItem) item;
      final String url = website.getUrl();
      if (!TextUtils.isEmpty(url)) {
        WebAddress webAddress = new WebAddress(url);
        mIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(webAddress.toString()));
      }

    } else if (item instanceof ImDataItem) {
      ImDataItem im = (ImDataItem) item;
      final boolean isEmail = im.isCreatedFromEmail();
      if (isEmail || im.isProtocolValid()) {
        final int protocol = isEmail ? Im.PROTOCOL_GOOGLE_TALK : im.getProtocol();

        if (isEmail) {
          // Use Google Talk string when using Email, and clear data
          // Uri so we don't try saving Email as primary.
          mSubtitle = Im.getProtocolLabel(context.getResources(), Im.PROTOCOL_GOOGLE_TALK, null);
          mDataUri = null;
        }

        String host = im.getCustomProtocol();
        String data = im.getData();
        if (protocol != Im.PROTOCOL_CUSTOM) {
          // Try bringing in a well-known host for specific protocols
          host = ContactsUtils.lookupProviderNameFromId(protocol);
        }

        if (!TextUtils.isEmpty(host) && !TextUtils.isEmpty(data)) {
          final String authority = host.toLowerCase();
          final Uri imUri =
              new Uri.Builder()
                  .scheme(Constants.SCHEME_IMTO)
                  .authority(authority)
                  .appendPath(data)
                  .build();
          mIntent = new Intent(Intent.ACTION_SENDTO, imUri);

          // If the address is also available for a video chat, we'll show the capability
          // as a secondary action.
          final int chatCapability = im.getChatCapability();
          final boolean isVideoChatCapable = (chatCapability & Im.CAPABILITY_HAS_CAMERA) != 0;
          final boolean isAudioChatCapable = (chatCapability & Im.CAPABILITY_HAS_VOICE) != 0;
          if (isVideoChatCapable || isAudioChatCapable) {
            mAlternateIntent =
                new Intent(Intent.ACTION_SENDTO, Uri.parse("xmpp:" + data + "?call"));
            if (isVideoChatCapable) {
              mAlternateIconRes = R.drawable.sym_action_videochat_holo_light;
              mAlternateIconDescriptionRes = R.string.video_chat;
            } else {
              mAlternateIconRes = R.drawable.sym_action_audiochat_holo_light;
              mAlternateIconDescriptionRes = R.string.audio_chat;
            }
          }
        }
      }
    } else if (item instanceof StructuredPostalDataItem) {
      StructuredPostalDataItem postal = (StructuredPostalDataItem) item;
      final String postalAddress = postal.getFormattedAddress();
      if (!TextUtils.isEmpty(postalAddress)) {
        mIntent = StructuredPostalUtils.getViewPostalAddressIntent(postalAddress);
      }
    }

    /*
     * New Feature by Mediatek Begin.
     *   Original Android's code:
     *
     *   CR ID: ALPS00308657
     *   Descriptions: RCS
     */

    else if (exMimeType != null && exMimeType.equals(item.getMimeType())) {
      String number = item.getContentValues().getAsString(Data.DATA1);
      mSubtitle = mPhoneAndSubtitle.get(number);
      int im = item.getContentValues().getAsInteger(Data.DATA5);
      int ft = item.getContentValues().getAsInteger(Data.DATA6);
      Log.i(TAG, "mSubtitle : " + mSubtitle + " | number : " + number);
      Intent intent =
          ExtensionManager.getInstance()
              .getContactDetailExtension()
              .getExtentionIntent(im, ft, ExtensionManager.COMMD_FOR_RCS);
      Log.i(TAG, "intent : " + intent + " | exMimeType : " + exMimeType);
      if (intent != null) {
        String name = item.getContentValues().getAsString(Contacts.DISPLAY_NAME);
        Log.i(TAG, "name : " + name + " | number : " + number);
        intent.putExtra(RCS_PHONE_NUMBER, number);
        intent.putExtra(RCS_DISPLAY_NAME, name);
        mIntent = intent;
      }
    }
    /*
     * New Feature by Mediatek End.
     */

    if (mIntent == null) {
      // Otherwise fall back to default VIEW action
      mIntent = new Intent(Intent.ACTION_VIEW);
      mIntent.setDataAndType(mDataUri, item.getMimeType());
    }

    mIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
  }