コード例 #1
0
ファイル: BrowserClient.cpp プロジェクト: remoe/osgearth-cef
bool BrowserClient::OnQuery(CefRefPtr<CefBrowser> browser,
                               CefRefPtr<CefFrame> frame,
                               int64 query_id,
                               const CefString& request,
                               bool persistent,
                               CefRefPtr<Callback> callback)
{
  // Parse JSON args
  std::string requestStr = request;
  OE_DEBUG << LC << "Query received: " << requestStr << std::endl;

  JsonArguments args(request);
  std::string command = args["command"];


  // Pass to callbacks to handle
  bool handled = false;
  if (!command.empty())
  {
    for( ExecuteCallbacks::iterator i = _callbacks.begin(); i != _callbacks.end(); )
    {
        if ( i->valid() )
        {
            osg::ref_ptr<ExecuteCallback::ReturnVal> ret = i->get()->execute(query_id, command, args, persistent ? callback : 0L);
            if (ret.valid())
            {
                handled = true;

                if (ret->errorCode == 0)
                {
                    callback->Success(ret->value);
                }
                else
                {
                    callback->Failure(ret->errorCode, ret->value);
                }

                break;
            }

            ++i;
        }
        else
        {
            i = _callbacks.erase( i );
        }
    }
  }


  // If unhandled call Failure callback
  if (!handled)
  {
      std::string result = "No handler found for query.";
      callback->Failure(404, result);
  }

  return true;
}
コード例 #2
0
ファイル: XCefCallback.cpp プロジェクト: Zion-007/XCef
/*virtual*/ bool XAsyncBrowserHandler::OnQuery(
	CefRefPtr<CefBrowser>			browser,
	CefRefPtr<CefFrame>				frame,
	int64							query_id,
	const CefString&				request,
	bool							persistent,
	CefRefPtr<BrowserCallback>		callback
	) /*OVERRIDE*/
{
	//const std::string &		message = request;
	XRPC_INFO 				rpc_info;
	CefString				exception_message;

	if (!XCefRpc::ParseJSONString(request, rpc_info, exception_message))
	{
		callback->Failure(0, exception_message);

		return false;
	}

	ProtocolFunctionHashMap & fn_protocol_map = GetData();
// 	{
// 		OutputDebugStringA(
// 			fn_protocol_map.begin()->first.c_str()
// 			);
// 		OutputDebugStringA("<<===>>");
// 		OutputDebugStringA(rpc_info.protocol_.ToString().c_str());
// 	}
	auto it_protocol = fn_protocol_map.find(rpc_info.protocol_);
	if (it_protocol == fn_protocol_map.end())
	{
		callback->Failure(
			0,
			XCefRpc::GetErrorByInfo(rpc_info.protocol_, XCefRpc::ERRINFO_INVALID_PROTOCOL)
			);
		return false;
	}
	FunctionHashMap & fn_map = it_protocol->second;
	auto it_fn = fn_map.find(rpc_info.method_);
	if (it_fn == fn_map.end())
	{
		callback->Failure(
			0,
			XCefRpc::GetError(
				rpc_info.protocol_,
				XCefRpc::ERRID_SERVER_ERROR,
				CefString("[Server]:Invalid method name")
				)
			);
		return false;
	}
	DCHECK_CB_INFO_IS_ACB(it_fn->second);
	it_fn->second.acb_query_(
		this, browser, frame, query_id, request, persistent, callback, 
		rpc_info
		);
	return true;
}
コード例 #3
0
ファイル: query_handler.cpp プロジェクト: loot/loot
// Called due to cefQuery execution in binding.html.
bool QueryHandler::OnQuery(CefRefPtr<CefBrowser> browser,
                           CefRefPtr<CefFrame> frame,
                           int64 query_id,
                           const CefString& request,
                           bool persistent,
                           CefRefPtr<Callback> callback) {
  try {
    auto query = createQuery(browser, frame, request.ToString());

    if (!query)
      return false;

    CefPostTask(TID_FILE, base::Bind(&Query::execute, query, callback));
  } catch (std::exception& e) {
    auto logger = lootState_.getLogger();
    if (logger) {
      logger->error("Failed to parse CEF query request \"{}\": {}",
        request.ToString(),
        e.what());
    }
    callback->Failure(-1, e.what());
  }

  return true;
}
コード例 #4
0
JNIEXPORT void JNICALL
Java_org_cef_callback_CefQueryCallback_1N_N_1Failure(JNIEnv* env,
                                                     jobject obj,
                                                     jint error_code,
                                                     jstring error_message) {
  CefRefPtr<CefMessageRouterBrowserSide::Callback> callback =
      GetCefFromJNIObject<CefMessageRouterBrowserSide::Callback>(
          env, obj, "CefQueryCallback");
  if (!callback.get())
    return;

  callback->Failure(error_code, GetJNIString(env, error_message));

  // Clear the reference added in ClientHandler::OnQuery.
  SetCefForJNIObject<CefMessageRouterBrowserSide::Callback>(env, obj, NULL,
                                                            "CefQueryCallback");
}
コード例 #5
0
ファイル: query_handler.cpp プロジェクト: silentdark/loot
// Called due to cefQuery execution in binding.html.
bool QueryHandler::OnQuery(CefRefPtr<CefBrowser> browser,
                           CefRefPtr<CefFrame> frame,
                           int64 query_id,
                           const CefString& request,
                           bool persistent,
                           CefRefPtr<Callback> callback) {
  YAML::Node parsedRequest;
  try {
    parsedRequest = JSON::parse(request.ToString());
  } catch (exception &e) {
    BOOST_LOG_TRIVIAL(error) << "Failed to parse CEF query request \"" << request.ToString() << "\": " << e.what();
    callback->Failure(-1, e.what());
    return true;
  }

  auto query = createQuery(browser, frame, parsedRequest);

  if (!query)
    return false;

  CefPostTask(TID_FILE, base::Bind(&Query::execute, query, callback));

  return true;
}