/**
   * native callback Indicates the beginning of a new load. This method will be called once for the
   * main frame.
   */
  private void loadStarted(String url, Bitmap favicon, int loadType, boolean isMainFrame) {
    mIsMainFrame = isMainFrame;

    if (isMainFrame || loadType == FRAME_LOADTYPE_STANDARD) {
      mLoadType = loadType;

      if (isMainFrame) {
        // Call onPageStarted for main frames.
        mCallbackProxy.onPageStarted(url, favicon);
        // as didFirstLayout() is only called for the main frame, reset
        // mFirstLayoutDone only for the main frames
        mFirstLayoutDone = false;
        mCommitted = false;
        // remove pending draw to block update until mFirstLayoutDone is
        // set to true in didFirstLayout()
        mWebViewCore.removeMessages(WebViewCore.EventHub.WEBKIT_DRAW);
      }

      // Note: only saves committed form data in standard load
      if (loadType == FRAME_LOADTYPE_STANDARD && mSettings.getSaveFormData()) {
        final WebHistoryItem h = mCallbackProxy.getBackForwardList().getCurrentItem();
        if (h != null) {
          String currentUrl = h.getUrl();
          if (currentUrl != null) {
            mDatabase.setFormData(currentUrl, getFormTextData());
          }
        }
      }
    }
  }
  /**
   * Create a new BrowserFrame to be used in an application.
   *
   * @param context An application context to use when retrieving assets.
   * @param w A WebViewCore used as the view for this frame.
   * @param proxy A CallbackProxy for posting messages to the UI thread and querying a client for
   *     information.
   * @param settings A WebSettings object that holds all settings. XXX: Called by WebCore thread.
   */
  public BrowserFrame(Context context, WebViewCore w, CallbackProxy proxy, WebSettings settings) {
    // Create a global JWebCoreJavaBridge to handle timers and
    // cookies in the WebCore thread.
    if (sJavaBridge == null) {
      sJavaBridge = new JWebCoreJavaBridge();
      // set WebCore native cache size
      sJavaBridge.setCacheSize(4 * 1024 * 1024);
      // initialize CacheManager
      CacheManager.init(context);
      // create CookieSyncManager with current Context
      CookieSyncManager.createInstance(context);
    }
    AssetManager am = context.getAssets();
    nativeCreateFrame(w, am, proxy.getBackForwardList());

    mSettings = settings;
    mContext = context;
    mCallbackProxy = proxy;
    mDatabase = WebViewDatabase.getInstance(context);
    mWebViewCore = w;

    if (WebView.LOGV_ENABLED) {
      Log.v(LOGTAG, "BrowserFrame constructor: this=" + this);
    }
  }
  /**
   * Handle messages posted to us.
   *
   * @param msg The message to handle.
   */
  @Override
  public void handleMessage(Message msg) {
    switch (msg.what) {
      case FRAME_COMPLETED:
        {
          if (mSettings.getSavePassword() && hasPasswordField()) {
            if (WebView.DEBUG) {
              Assert.assertNotNull(mCallbackProxy.getBackForwardList().getCurrentItem());
            }
            WebAddress uri =
                new WebAddress(mCallbackProxy.getBackForwardList().getCurrentItem().getUrl());
            String schemePlusHost = uri.mScheme + uri.mHost;
            String[] up = mDatabase.getUsernamePassword(schemePlusHost);
            if (up != null && up[0] != null) {
              setUsernamePassword(up[0], up[1]);
            }
          }
          CacheManager.trimCacheIfNeeded();
          break;
        }

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

      default:
        break;
    }
  }
Example #4
0
  public MoPubView(Context context, AttributeSet attrs) {
    super(context, attrs);

    ManifestUtils.checkWebViewActivitiesDeclared(context);

    mContext = context;
    mScreenVisibility = getVisibility();

    setHorizontalScrollBarEnabled(false);
    setVerticalScrollBarEnabled(false);

    // There is a rare bug in Froyo/2.2 where creation of a WebView causes a
    // NullPointerException. (http://code.google.com/p/android/issues/detail?id=10789)
    // It happens when the WebView can't access the local file store to make a cache file.
    // Here, we'll work around it by trying to create a file store and then just go inert
    // if it's not accessible.
    if (WebViewDatabase.getInstance(context) == null) {
      MoPubLog.e(
          "Disabling MoPub. Local cache file is inaccessible so MoPub will "
              + "fail if we try to create a WebView. Details of this Android bug found at:"
              + "http://code.google.com/p/android/issues/detail?id=10789");
      return;
    }

    mAdViewController = AdViewControllerFactory.create(context, this);
    registerScreenStateBroadcastReceiver();
  }
Example #5
0
  public MoPubView(Context context, AttributeSet attrs) {
    super(context, attrs);

    mContext = context;
    mIsInForeground = (getVisibility() == VISIBLE);
    mLocationAwareness = LocationAwareness.LOCATION_AWARENESS_NORMAL;
    mLocationPrecision = DEFAULT_LOCATION_PRECISION;

    setHorizontalScrollBarEnabled(false);
    setVerticalScrollBarEnabled(false);

    // There is a rare bug in Froyo/2.2 where creation of a WebView causes a
    // NullPointerException. (http://code.google.com/p/android/issues/detail?id=10789)
    // It happens when the WebView can't access the local file store to make a cache file.
    // Here, we'll work around it by trying to create a file store and then just go inert
    // if it's not accessible.
    if (WebViewDatabase.getInstance(context) == null) {
      Log.e(
          "MoPub",
          "Disabling MoPub. Local cache file is inaccessible so MoPub will "
              + "fail if we try to create a WebView. Details of this Android bug found at:"
              + "http://code.google.com/p/android/issues/detail?id=10789");
      return;
    }

    initVersionDependentAdView(context);
    registerScreenStateBroadcastReceiver();
  }
  /**
   * 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
    }
  }
  /**
   * Create a new BrowserFrame to be used in an application.
   *
   * @param context An application context to use when retrieving assets.
   * @param w A WebViewCore used as the view for this frame.
   * @param proxy A CallbackProxy for posting messages to the UI thread and querying a client for
   *     information.
   * @param settings A WebSettings object that holds all settings. XXX: Called by WebCore thread.
   */
  public BrowserFrame(
      Context context,
      WebViewCore w,
      CallbackProxy proxy,
      WebSettings settings,
      Map<String, Object> javascriptInterfaces) {

    Context appContext = context.getApplicationContext();

    // Create a global JWebCoreJavaBridge to handle timers and
    // cookies in the WebCore thread.
    if (sJavaBridge == null) {
      sJavaBridge = new JWebCoreJavaBridge();
      // set WebCore native cache size
      ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
      if (am.getMemoryClass() > 16) {
        sJavaBridge.setCacheSize(8 * 1024 * 1024);
      } else {
        sJavaBridge.setCacheSize(4 * 1024 * 1024);
      }
      // initialize CacheManager
      CacheManager.init(appContext);
      // create CookieSyncManager with current Context
      CookieSyncManager.createInstance(appContext);
      // create PluginManager with current Context
      PluginManager.getInstance(appContext);
    }

    if (sConfigCallback == null) {
      sConfigCallback =
          new ConfigCallback((WindowManager) appContext.getSystemService(Context.WINDOW_SERVICE));
      ViewRootImpl.addConfigCallback(sConfigCallback);
    }
    sConfigCallback.addHandler(this);

    mJavaScriptObjects = javascriptInterfaces;
    if (mJavaScriptObjects == null) {
      mJavaScriptObjects = new HashMap<String, Object>();
    }
    mRemovedJavaScriptObjects = new HashSet<Object>();

    mSettings = settings;
    mContext = context;
    mCallbackProxy = proxy;
    mDatabase = WebViewDatabase.getInstance(appContext);
    mWebViewCore = w;

    mSearchBox = new SearchBoxImpl(mWebViewCore, mCallbackProxy);
    mJavaScriptObjects.put(SearchBoxImpl.JS_INTERFACE_NAME, mSearchBox);

    AssetManager am = context.getAssets();
    nativeCreateFrame(w, am, proxy.getBackForwardList());

    if (DebugFlags.BROWSER_FRAME) {
      Log.v(LOGTAG, "BrowserFrame constructor: this=" + this);
    }
  }
 @SuppressWarnings("unused")
 private void saveFormData(HashMap<String, String> data) {
   if (mSettings.getSaveFormData()) {
     final WebHistoryItem h = mCallbackProxy.getBackForwardList().getCurrentItem();
     if (h != null) {
       String url = WebTextView.urlForAutoCompleteData(h.getUrl());
       if (url != null) {
         mDatabase.setFormData(url, data);
       }
     }
   }
 }
Example #9
0
  protected static void clearTraces() {
    CustomWebView WV = (CustomWebView) webLayout.findViewById(R.id.browser_page);
    if (WV != null) {
      WV.clearHistory();
      WV.clearCache(true);
    }

    WebViewDatabase wDB = WebViewDatabase.getInstance(activity);
    wDB.clearFormData();

    CookieSyncManager.createInstance(activity);
    CookieManager cookieManager = CookieManager.getInstance();
    cookieManager.removeAllCookie();
    // Usefull for future commits:
    //			cookieManager.setAcceptCookie(false)
    //
    //			WebView webview = new WebView(this);
    //			WebSettings ws = webview.getSettings();
    //			ws.setSaveFormData(false);
    //			ws.setSavePassword(false); // Not needed for API level 18 or greater (deprecat
  }
  /**
   * 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;
    }
  }
Example #11
0
  public MoPubView(Context context, AttributeSet attrs) {
    super(context, attrs);

    // There is a rare bug in Froyo/2.2 where creation of a WebView causes a
    // NullPointerException. (http://code.google.com/p/android/issues/detail?id=10789)
    // It happens when the WebView can't access the local file store to make a cache file.
    // Here, we'll work around it by trying to create a file store and then just go inert
    // if it's not accessible.
    if (WebViewDatabase.getInstance(context) == null) {
      Log.e(
          "MoPub",
          "Disabling MoPub. Local cache file is inaccessbile so MoPub will "
              + "fail if we try to create a WebView. Details of this Android bug found at:"
              + "http://code.google.com/p/android/issues/detail?id=10789");
      return;
    }

    // The AdView doesn't need to be in the view hierarchy until an ad is loaded
    mAdView = new AdView(context, this);
  }
  /**
   * Start loading a resource.
   *
   * @param loaderHandle The native ResourceLoader that is the target of the data.
   * @param url The url to load.
   * @param method The http method.
   * @param headers The http headers.
   * @param postData If the method is "POST" postData is sent as the request body. Is null when
   *     empty.
   * @param cacheMode The cache mode to use when loading this resource.
   * @param isHighPriority True if this resource needs to be put at the front of the network queue.
   * @param synchronous True if the load is synchronous.
   * @return A newly created LoadListener object.
   */
  private LoadListener startLoadingResource(
      int loaderHandle,
      String url,
      String method,
      HashMap headers,
      byte[] postData,
      int cacheMode,
      boolean isHighPriority,
      boolean synchronous) {
    PerfChecker checker = new PerfChecker();

    if (mSettings.getCacheMode() != WebSettings.LOAD_DEFAULT) {
      cacheMode = mSettings.getCacheMode();
    }

    if (method.equals("POST")) {
      // Don't use the cache on POSTs when issuing a normal POST
      // request.
      if (cacheMode == WebSettings.LOAD_NORMAL) {
        cacheMode = WebSettings.LOAD_NO_CACHE;
      }
      if (mSettings.getSavePassword() && hasPasswordField()) {
        try {
          if (WebView.DEBUG) {
            Assert.assertNotNull(mCallbackProxy.getBackForwardList().getCurrentItem());
          }
          WebAddress uri =
              new WebAddress(mCallbackProxy.getBackForwardList().getCurrentItem().getUrl());
          String schemePlusHost = uri.mScheme + uri.mHost;
          String[] ret = getUsernamePassword();
          // Has the user entered a username/password pair and is
          // there some POST data
          if (ret != null && postData != null && ret[0].length() > 0 && ret[1].length() > 0) {
            // 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(ret[0]))
                && postString.contains(URLEncoder.encode(ret[1]))) {
              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, ret[0], ret[1]);
                }
              } else {
                // CallbackProxy will handle creating the resume
                // message
                mCallbackProxy.onSavePassword(schemePlusHost, ret[0], ret[1], null);
              }
            }
          }
        } catch (ParseException ex) {
          // if it is bad uri, don't save its password
        }
      }
    }

    // is this resource the main-frame top-level page?
    boolean isMainFramePage = mIsMainFrame;

    if (WebView.LOGV_ENABLED) {
      Log.v(
          LOGTAG,
          "startLoadingResource: url="
              + url
              + ", method="
              + method
              + ", postData="
              + postData
              + ", isHighPriority="
              + isHighPriority
              + ", isMainFramePage="
              + isMainFramePage);
    }

    // Create a LoadListener
    LoadListener loadListener =
        LoadListener.getLoadListener(
            mContext, this, url, loaderHandle, synchronous, isMainFramePage);

    mCallbackProxy.onLoadResource(url);

    if (LoadListener.getNativeLoaderCount() > MAX_OUTSTANDING_REQUESTS) {
      loadListener.error(
          android.net.http.EventHandler.ERROR,
          mContext.getString(com.android.internal.R.string.httpErrorTooManyRequests));
      loadListener.notifyError();
      loadListener.tearDown();
      return null;
    }

    // during synchronous load, the WebViewCore thread is blocked, so we
    // need to endCacheTransaction first so that http thread won't be
    // blocked in setupFile() when createCacheFile.
    if (synchronous) {
      CacheManager.endCacheTransaction();
    }

    FrameLoader loader = new FrameLoader(loadListener, mSettings, method, isHighPriority);
    loader.setHeaders(headers);
    loader.setPostData(postData);
    // Set the load mode to the mode used for the current page.
    // If WebKit wants validation, go to network directly.
    loader.setCacheMode(
        headers.containsKey("If-Modified-Since") || headers.containsKey("If-None-Match")
            ? WebSettings.LOAD_NO_CACHE
            : cacheMode);
    // Set referrer to current URL?
    if (!loader.executeLoad()) {
      checker.responseAlert("startLoadingResource fail");
    }
    checker.responseAlert("startLoadingResource succeed");

    if (synchronous) {
      CacheManager.startCacheTransaction();
    }

    return !synchronous ? loadListener : null;
  }
Example #13
0
 public final boolean b() {
   dw dw1 = a;
   Context context = dw.a(dw1.a);
   return dw1.b.b(context) && WebViewDatabase.getInstance(context) != null;
 }