void ContextMenuHandler::OnBeforeContextMenu(CefRefPtr<CefBrowser> browser,
                                             CefRefPtr<CefFrame> frame,
                                             CefRefPtr<CefContextMenuParams> params,
                                             CefRefPtr<CefMenuModel> model) {
  JNIEnv* env = GetJNIEnv();
  if (!env)
    return;

  jobject jparams = NewJNIObject(env, "org/cef/callback/CefContextMenuParams_N");
  if (!jparams)
    return;
  jobject jmodel = NewJNIObject(env, "org/cef/callback/CefMenuModel_N");
  if (!jmodel)
    return;

  SetCefForJNIObject(env, jparams, params.get(), "CefContextMenuParams");
  SetCefForJNIObject(env, jmodel, model.get(), "CefMenuModel");

  JNI_CALL_VOID_METHOD(env, jhandler_,
                       "onBeforeContextMenu",
                       "(Lorg/cef/browser/CefBrowser;Lorg/cef/callback/CefContextMenuParams;"
                       "Lorg/cef/callback/CefMenuModel;)V",
                       GetJNIBrowser(browser),
                       jparams,
                       jmodel);

  // Do not keep references to |params| or |model| outside of this callback.
  SetCefForJNIObject<CefContextMenuParams>(env, jparams, NULL, "CefContextMenuParams");
  SetCefForJNIObject<CefMenuModel>(env, jmodel, NULL, "CefMenuModel");
}
Пример #2
0
CefRefPtr<CefResourceHandler> SchemeHandlerFactory::Create(
    CefRefPtr<CefBrowser> browser,
    CefRefPtr<CefFrame> frame,
    const CefString& scheme_name,
    CefRefPtr<CefRequest> request) {
  JNIEnv* env = GetJNIEnv();
  if (!env)
    return NULL;

  jobject jRequest = NewJNIObject(env, "org/cef/network/CefRequest_N");
  if (jRequest != NULL)
    SetCefForJNIObject(env, jRequest, request.get(), "CefRequest");

  jobject jResourceHandler = NULL;
  JNI_CALL_METHOD(env, jfactory_, "create",
                  "(Lorg/cef/browser/CefBrowser;Lorg/cef/browser/"
                  "CefFrame;Ljava/lang/String;Lorg/cef/"
                  "network/CefRequest;)Lorg/cef/handler/CefResourceHandler;",
                  Object, jResourceHandler, GetJNIBrowser(browser),
                  GetJNIFrame(env, frame), NewJNIString(env, scheme_name),
                  jRequest);

  if (jRequest != NULL)
    SetCefForJNIObject<CefRequest>(env, jRequest, NULL, "CefRequest");

  if (!jResourceHandler)
    return NULL;
  CefRefPtr<CefResourceHandler> result =
      new ResourceHandler(env, jResourceHandler);
  return result;
}
JNIEXPORT void JNICALL Java_org_cef_network_CefResponse_1N_N_1CefResponse_1CTOR
  (JNIEnv *env, jobject obj) {
  CefRefPtr<CefResponse> response = CefResponse::Create();
  if (!response.get())
    return;
  SetCefForJNIObject(env, obj, response.get(), "CefResponse");
}
bool ContextMenuHandler::OnContextMenuCommand(CefRefPtr<CefBrowser> browser,
                                              CefRefPtr<CefFrame> frame,
                                              CefRefPtr<CefContextMenuParams> params,
                                              int command_id,
                                              EventFlags event_flags) {
  JNIEnv* env = GetJNIEnv();
  if (!env)
    return false;

  jobject jparams = NewJNIObject(env, "org/cef/callback/CefContextMenuParams_N");
  if (!jparams)
    return false;
  SetCefForJNIObject(env, jparams, params.get(), "CefContextMenuParams");

  jboolean result = JNI_FALSE;
  JNI_CALL_METHOD(env, jhandler_,
                  "onContextMenuCommand",
                  "(Lorg/cef/browser/CefBrowser;Lorg/cef/callback/CefContextMenuParams;II)Z",
                  Boolean,
                  result,
                  GetJNIBrowser(browser),
                  jparams,
                  (jint)command_id,
                  (jint)event_flags);

  // Do not keep references to |params| or |model| outside of this callback.
  SetCefForJNIObject<CefContextMenuParams>(env, jparams, NULL, "CefContextMenuParams");
  return (result != JNI_FALSE);
}
bool DragHandler::OnDragEnter(CefRefPtr<CefBrowser> browser,
                             CefRefPtr<CefDragData> dragData,
                             CefDragHandler::DragOperationsMask mask) {
  JNIEnv* env = GetJNIEnv();
  if (!env)
    return false;

  jobject jdragdata = NewJNIObject(env, "org/cef/callback/CefDragData_N");
  if (!jdragdata)
    return false;
  SetCefForJNIObject(env, jdragdata, dragData.get(), "CefDragData");

  jboolean result = JNI_FALSE;
  JNI_CALL_METHOD(env, jhandler_,
                  "onDragEnter",
                  "(Lorg/cef/browser/CefBrowser;Lorg/cef/callback/CefDragData;I)Z",
                  Boolean,
                  result,
                  GetJNIBrowser(browser),
                  jdragdata,
                  (jint)mask);

  //Remove native reference from java class
  SetCefForJNIObject<CefDragData>(env, jdragdata, NULL, "CefDragData");
  return (result != JNI_FALSE);
}
Пример #6
0
bool JSDialogHandler::OnBeforeUnloadDialog(
    CefRefPtr<CefBrowser> browser,
    const CefString& message_text,
    bool is_reload,
    CefRefPtr<CefJSDialogCallback> callback) {
  JNIEnv* env = GetJNIEnv();
  if (!env)
    return false;

  jobject jcallback =
      NewJNIObject(env, "org/cef/callback/CefJSDialogCallback_N");
  if (!jcallback)
    return false;
  SetCefForJNIObject(env, jcallback, callback.get(), "CefJSDialogCallback");

  jboolean jresult = JNI_FALSE;
  JNI_CALL_METHOD(env, jhandler_, "onBeforeUnloadDialog",
                  "(Lorg/cef/browser/CefBrowser;Ljava/lang/String;ZLorg/cef/"
                  "callback/CefJSDialogCallback;)Z",
                  Boolean, jresult, GetJNIBrowser(browser),
                  NewJNIString(env, message_text),
                  (is_reload ? JNI_TRUE : JNI_FALSE), jcallback);

  if (jresult == JNI_FALSE) {
    // If the java method returns "false", the callback won't be used and
    // therefore the reference can be removed.
    SetCefForJNIObject<CefJSDialogCallback>(env, jcallback, NULL,
                                            "CefJSDialogCallback");
  }
  return (jresult != JNI_FALSE);
}
JNIEXPORT void JNICALL
  Java_org_cef_misc_CefPrintSettings_1N_N_1CefPrintSettings_1CTOR
    (JNIEnv *env, jobject obj) {
  CefRefPtr<CefPrintSettings> settings = CefPrintSettings::Create();
  if (!settings.get())
    return;
  SetCefForJNIObject(env, obj, settings.get(), "CefPrintSettings");
}
Пример #8
0
bool JSDialogHandler::OnJSDialog(CefRefPtr<CefBrowser> browser,
                                 const CefString& origin_url,
                                 CefJSDialogHandler::JSDialogType dialog_type,
                                 const CefString& message_text,
                                 const CefString& default_prompt_text,
                                 CefRefPtr<CefJSDialogCallback> callback,
                                 bool& suppress_message) {
  JNIEnv* env = GetJNIEnv();
  if (!env)
    return false;

  jobject jdialogType = NULL;
  switch (dialog_type) {
    default:
      JNI_CASE(env, "org/cef/handler/CefJSDialogHandler$JSDialogType",
               JSDIALOGTYPE_ALERT, jdialogType);
      JNI_CASE(env, "org/cef/handler/CefJSDialogHandler$JSDialogType",
               JSDIALOGTYPE_CONFIRM, jdialogType);
      JNI_CASE(env, "org/cef/handler/CefJSDialogHandler$JSDialogType",
               JSDIALOGTYPE_PROMPT, jdialogType);
  }

  jobject jboolRef = NewJNIBoolRef(env, suppress_message);
  if (!jboolRef)
    return false;

  jobject jcallback =
      NewJNIObject(env, "org/cef/callback/CefJSDialogCallback_N");
  if (!jcallback)
    return false;
  SetCefForJNIObject(env, jcallback, callback.get(), "CefJSDialogCallback");

  jboolean jresult = JNI_FALSE;
  JNI_CALL_METHOD(
      env, jhandler_, "onJSDialog",
      "(Lorg/cef/browser/CefBrowser;Ljava/lang/String;"
      "Lorg/cef/handler/CefJSDialogHandler$JSDialogType;Ljava/lang/String;"
      "Ljava/lang/String;Lorg/cef/callback/CefJSDialogCallback;Lorg/cef/misc/"
      "BoolRef;)Z",
      Boolean, jresult, GetJNIBrowser(browser), NewJNIString(env, origin_url),
      jdialogType, NewJNIString(env, message_text),
      NewJNIString(env, default_prompt_text), jcallback, jboolRef);

  suppress_message = GetJNIBoolRef(env, jboolRef);

  if (jresult == JNI_FALSE) {
    // If the java method returns "false", the callback won't be used and
    // therefore the reference can be removed.
    SetCefForJNIObject<CefJSDialogCallback>(env, jcallback, NULL,
                                            "CefJSDialogCallback");
  }
  return (jresult != JNI_FALSE);
}
Пример #9
0
CefRefPtr<CefDownloadHandler> ClientHandler::GetDownloadHandler() {
  CefRefPtr<CefDownloadHandler> result = NULL;
  BEGIN_ENV(env)
  jobject handler = NULL;
  JNI_CALL_METHOD(env, jhandler_, "getDownloadHandler", "()Lorg/cef/handler/CefDownloadHandler;", Object, handler);
  if (handler) {
    result = GetCefFromJNIObject<CefDownloadHandler>(env, handler, "CefDownloadHandler");
    if (!result.get()) {
      result = new DownloadHandler(env, handler);
      SetCefForJNIObject(env, handler, result.get(), "CefDownloadHandler");
    }
  }
  END_ENV(env)
  return result;
}
Пример #10
0
JNIEXPORT jobject JNICALL
Java_org_cef_network_CefCookieManager_1N_N_1GetGlobalManager(JNIEnv* env,
                                                             jclass cls) {
  // TODO(JCEF): Expose the callback object.
  CefRefPtr<CefCookieManager> manager =
      CefCookieManager::GetGlobalManager(NULL);
  if (!manager.get())
    return NULL;

  jobject jManager = NewJNIObject(env, cls);
  if (!jManager)
    return NULL;

  SetCefForJNIObject(env, jManager, manager.get(), "CefCookieManager");
  return jManager;
}
JNIEXPORT jobject JNICALL Java_org_cef_misc_CefPrintSettings_1N_N_1Copy
  (JNIEnv *env, jobject obj) {
  CefRefPtr<CefPrintSettings> settings =
      GetCefFromJNIObject<CefPrintSettings>(env, obj, "CefPrintSettings");
  if (!settings)
    return NULL;

  jobject jresult = NewJNIObject(env, "org/cef/misc/CefPrintSettings_N");
  if (!jresult)
    return NULL;

  CefRefPtr<CefPrintSettings> copy_of_settings = settings->Copy();
  if (!copy_of_settings)
    return NULL;
  SetCefForJNIObject(env, jresult, copy_of_settings.get(), "CefPrintSettings");
  return jresult;
}
Пример #12
0
JNIEXPORT jobject JNICALL
Java_org_cef_network_CefCookieManager_1N_N_1CreateManager(
    JNIEnv* env,
    jclass cls,
    jstring jpath,
    jboolean jpersistSessionCookies) {
  // TODO(JCEF): Expose the callback object.
  CefRefPtr<CefCookieManager> manager = CefCookieManager::CreateManager(
      GetJNIString(env, jpath), (jpersistSessionCookies != JNI_FALSE), NULL);
  if (!manager.get())
    return NULL;

  jobject jManager = NewJNIObject(env, cls);
  if (!jManager)
    return NULL;

  SetCefForJNIObject(env, jManager, manager.get(), "CefCookieManager");
  return jManager;
}
void LifeSpanHandler::OnAfterCreated(CefRefPtr<CefBrowser> browser) {
  JNIEnv* env = GetJNIEnv();
  if (!env || jbrowsers_.empty())
    return;

  jobject jbrowser = jbrowsers_.front();
  jbrowsers_.pop_front();

  CefRefPtr<ClientHandler> client = (ClientHandler*)browser->GetHost()->GetClient().get();
  client->OnAfterCreated();

  if (SetCefForJNIObject(env, jbrowser, browser.get(), "CefBrowser")) {
    JNI_CALL_VOID_METHOD(env, jhandler_,
                         "onAfterCreated",
                         "(Lorg/cef/browser/CefBrowser;)V",
                         jbrowser);
  }
  env->DeleteGlobalRef(jbrowser);
}
JNIEXPORT void JNICALL Java_org_cef_handler_CefClientHandler_N_1CefClientHandler_1CTOR
  (JNIEnv *env, jobject clientHandler) {
  CefRefPtr<ClientHandler> client = new ClientHandler(env, clientHandler);
  SetCefForJNIObject(env, clientHandler, client.get(), "CefClientHandler");
}