Add a new CefGetGeolocation function for retrieving geolocation information via an API callback (issue #764).

git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@868 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
Marshall Greenblatt 2012-10-19 18:39:44 +00:00
parent e1f2be1785
commit e45ff9e838
15 changed files with 754 additions and 1 deletions

View File

@ -244,6 +244,7 @@
'tests/unittests/cookie_unittest.cc',
'tests/unittests/dialog_unittest.cc',
'tests/unittests/dom_unittest.cc',
'tests/unittests/geolocation_unittest.cc',
'tests/unittests/jsdialog_unittest.cc',
'tests/unittests/navigation_unittest.cc',
'tests/unittests/process_message_unittest.cc',
@ -815,6 +816,7 @@
'libcef/browser/download_manager_delegate.h',
'libcef/browser/frame_host_impl.cc',
'libcef/browser/frame_host_impl.h',
'libcef/browser/geolocation_impl.cc',
'libcef/browser/internal_scheme_handler.cc',
'libcef/browser/internal_scheme_handler.h',
'libcef/browser/javascript_dialog.h',

View File

@ -27,6 +27,7 @@
'include/cef_download_item.h',
'include/cef_focus_handler.h',
'include/cef_frame.h',
'include/cef_geolocation.h',
'include/cef_geolocation_handler.h',
'include/cef_jsdialog_handler.h',
'include/cef_keyboard_handler.h',
@ -73,6 +74,7 @@
'include/capi/cef_download_item_capi.h',
'include/capi/cef_focus_handler_capi.h',
'include/capi/cef_frame_capi.h',
'include/capi/cef_geolocation_capi.h',
'include/capi/cef_geolocation_handler_capi.h',
'include/capi/cef_jsdialog_handler_capi.h',
'include/capi/cef_keyboard_handler_capi.h',
@ -164,6 +166,8 @@
'libcef_dll/cpptoc/geolocation_callback_cpptoc.h',
'libcef_dll/ctocpp/geolocation_handler_ctocpp.cc',
'libcef_dll/ctocpp/geolocation_handler_ctocpp.h',
'libcef_dll/ctocpp/get_geolocation_callback_ctocpp.cc',
'libcef_dll/ctocpp/get_geolocation_callback_ctocpp.h',
'libcef_dll/cpptoc/jsdialog_callback_cpptoc.cc',
'libcef_dll/cpptoc/jsdialog_callback_cpptoc.h',
'libcef_dll/ctocpp/jsdialog_handler_ctocpp.cc',
@ -310,6 +314,8 @@
'libcef_dll/ctocpp/geolocation_callback_ctocpp.h',
'libcef_dll/cpptoc/geolocation_handler_cpptoc.cc',
'libcef_dll/cpptoc/geolocation_handler_cpptoc.h',
'libcef_dll/cpptoc/get_geolocation_callback_cpptoc.cc',
'libcef_dll/cpptoc/get_geolocation_callback_cpptoc.h',
'libcef_dll/ctocpp/jsdialog_callback_ctocpp.cc',
'libcef_dll/ctocpp/jsdialog_callback_ctocpp.h',
'libcef_dll/cpptoc/jsdialog_handler_cpptoc.cc',

View File

@ -0,0 +1,80 @@
// Copyright (c) 2012 Marshall A. Greenblatt. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the name Chromium Embedded
// Framework nor the names of its contributors may be used to endorse
// or promote products derived from this software without specific prior
// written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// ---------------------------------------------------------------------------
//
// This file was generated by the CEF translator tool and should not edited
// by hand. See the translator.README.txt file in the tools directory for
// more information.
//
#ifndef CEF_INCLUDE_CAPI_CEF_GEOLOCATION_CAPI_H_
#define CEF_INCLUDE_CAPI_CEF_GEOLOCATION_CAPI_H_
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include "include/capi/cef_base_capi.h"
///
// Request a one-time geolocation update. This function bypasses any user
// permission checks so should only be used by code that is allowed to access
// location information.
///
CEF_EXPORT int cef_get_geolocation(
struct _cef_get_geolocation_callback_t* callback);
///
// Implement this structure to receive geolocation updates. The functions of
// this structure will be called on the browser process UI thread.
///
typedef struct _cef_get_geolocation_callback_t {
///
// Base structure.
///
cef_base_t base;
///
// Called with the 'best available' location information or, if the location
// update failed, with error information.
///
void (CEF_CALLBACK *on_location_update)(
struct _cef_get_geolocation_callback_t* self,
const struct _cef_geoposition_t* position);
} cef_get_geolocation_callback_t;
#ifdef __cplusplus
}
#endif
#endif // CEF_INCLUDE_CAPI_CEF_GEOLOCATION_CAPI_H_

66
include/cef_geolocation.h Normal file
View File

@ -0,0 +1,66 @@
// Copyright (c) 2012 Marshall A. Greenblatt. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the name Chromium Embedded
// Framework nor the names of its contributors may be used to endorse
// or promote products derived from this software without specific prior
// written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// ---------------------------------------------------------------------------
//
// The contents of this file must follow a specific format in order to
// support the CEF translator tool. See the translator.README.txt file in the
// tools directory for more information.
//
#ifndef CEF_INCLUDE_CEF_GEOLOCATION_H_
#define CEF_INCLUDE_CEF_GEOLOCATION_H_
#pragma once
#include "include/cef_base.h"
///
// Implement this interface to receive geolocation updates. The methods of this
// class will be called on the browser process UI thread.
///
/*--cef(source=client)--*/
class CefGetGeolocationCallback : public virtual CefBase {
public:
///
// Called with the 'best available' location information or, if the location
// update failed, with error information.
///
/*--cef()--*/
virtual void OnLocationUpdate(const CefGeoposition& position) =0;
};
///
// Request a one-time geolocation update. This function bypasses any user
// permission checks so should only be used by code that is allowed to access
// location information.
///
/*--cef()--*/
bool CefGetGeolocation(CefRefPtr<CefGetGeolocationCallback> callback);
#endif // CEF_INCLUDE_CEF_GEOLOCATION_H_

View File

@ -1321,6 +1321,74 @@ enum cef_file_dialog_mode_t {
FILE_DIALOG_SAVE,
};
///
// Geoposition error codes.
///
enum cef_geoposition_error_code_t {
GEOPOSITON_ERROR_NONE = 0,
GEOPOSITON_ERROR_PERMISSION_DENIED,
GEOPOSITON_ERROR_POSITION_UNAVAILABLE,
GEOPOSITON_ERROR_TIMEOUT,
};
///
// Structure representing geoposition information. The properties of this
// structure correspond to those of the JavaScript Position object although
// their types may differ.
///
typedef struct _cef_geoposition_t {
///
// Latitude in decimal degrees north (WGS84 coordinate frame).
///
double latitude;
///
// Longitude in decimal degrees west (WGS84 coordinate frame).
///
double longitude;
///
// Altitude in meters (above WGS84 datum).
///
double altitude;
///
// Accuracy of horizontal position in meters.
///
double accuracy;
///
// Accuracy of altitude in meters.
///
double altitude_accuracy;
///
// Heading in decimal degrees clockwise from true north.
///
double heading;
///
// Horizontal component of device velocity in meters per second.
///
double speed;
///
// Time of position measurement in miliseconds since Epoch in UTC time. This
// is taken from the host computer's system clock.
///
cef_time_t timestamp;
///
// Error code, see enum above.
///
cef_geoposition_error_code_t error_code;
///
// Human-readable error message.
///
cef_string_t error_message;
} cef_geoposition_t;
#ifdef __cplusplus
}
#endif

View File

@ -1,4 +1,4 @@
// Copyright (c) 2011 Marshall A. Greenblatt. All rights reserved.
// Copyright (c) 2012 Marshall A. Greenblatt. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
@ -589,4 +589,34 @@ class CefProxyInfo : public CefStructBase<CefProxyInfoTraits> {
CefString ProxyList() const { return CefString(&proxyList); }
};
struct CefGeopositionTraits {
typedef cef_geoposition_t struct_type;
static inline void init(struct_type* s) {}
static inline void clear(struct_type* s) {
cef_string_clear(&s->error_message);
}
static inline void set(const struct_type* src, struct_type* target,
bool copy) {
target->latitude = src->latitude;
target->longitude = src->longitude;
target->altitude = src->altitude;
target->accuracy = src->accuracy;
target->altitude_accuracy = src->altitude_accuracy;
target->heading = src->heading;
target->speed = src->speed;
target->timestamp = src->timestamp;
target->error_code = src->error_code;
cef_string_set(src->error_message.str, src->error_message.length,
&target->error_message, copy);
}
};
///
// Class representing a geoposition.
///
typedef CefStructBase<CefGeopositionTraits> CefGeoposition;
#endif // CEF_INCLUDE_INTERNAL_CEF_TYPES_WRAPPERS_H_

View File

@ -0,0 +1,79 @@
// Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that can
// be found in the LICENSE file.
#include "include/cef_geolocation.h"
#include "libcef/browser/context.h"
#include "libcef/browser/thread_util.h"
#include "libcef/common/time_util.h"
#include "base/logging.h"
#include "content/browser/geolocation/geolocation_provider.h"
#include "content/public/common/geoposition.h"
namespace {
void SetPosition(const content::Geoposition& source, CefGeoposition& target) {
target.latitude = source.latitude;
target.longitude = source.longitude;
target.altitude = source.altitude;
target.accuracy = source.accuracy;
target.altitude_accuracy = source.altitude_accuracy;
target.heading = source.heading;
target.speed = source.speed;
cef_time_from_basetime(source.timestamp, target.timestamp);
switch (source.error_code) {
case content::Geoposition::ERROR_CODE_NONE:
target.error_code = GEOPOSITON_ERROR_NONE;
break;
case content::Geoposition::ERROR_CODE_PERMISSION_DENIED:
target.error_code = GEOPOSITON_ERROR_PERMISSION_DENIED;
break;
case content::Geoposition::ERROR_CODE_POSITION_UNAVAILABLE:
target.error_code = GEOPOSITON_ERROR_POSITION_UNAVAILABLE;
break;
case content::Geoposition::ERROR_CODE_TIMEOUT:
target.error_code = GEOPOSITON_ERROR_TIMEOUT;
break;
}
CefString(&target.error_message) = source.error_message;
}
void LocationCallback(CefRefPtr<CefGetGeolocationCallback> callback,
const content::Geoposition& position) {
if (CEF_CURRENTLY_ON_UIT()) {
CefGeoposition cef_position;
SetPosition(position, cef_position);
callback->OnLocationUpdate(cef_position);
} else {
CEF_POST_TASK(CEF_UIT, base::Bind(LocationCallback, callback, position));
}
}
} // namespace
bool CefGetGeolocation(CefRefPtr<CefGetGeolocationCallback> callback) {
if (!CONTEXT_STATE_VALID()) {
NOTREACHED() << "context not valid";
return false;
}
if (!callback.get()) {
NOTREACHED() << "invalid parameter";
return false;
}
if (CEF_CURRENTLY_ON_IOT()) {
GeolocationProvider* provider = GeolocationProvider::GetInstance();
if (provider) {
provider->RequestCallback(base::Bind(LocationCallback, callback));
return true;
}
return false;
} else {
CEF_POST_TASK(CEF_IOT,
base::Bind(base::IgnoreResult(CefGetGeolocation), callback));
return true;
}
}

View File

@ -0,0 +1,57 @@
// Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
//
// ---------------------------------------------------------------------------
//
// This file was generated by the CEF translator tool. If making changes by
// hand only do so within the body of existing method and function
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
#include "libcef_dll/cpptoc/get_geolocation_callback_cpptoc.h"
// MEMBER FUNCTIONS - Body may be edited by hand.
void CEF_CALLBACK get_geolocation_callback_on_location_update(
struct _cef_get_geolocation_callback_t* self,
const struct _cef_geoposition_t* position) {
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
DCHECK(self);
if (!self)
return;
// Verify param: position; type: struct_byref_const
DCHECK(position);
if (!position)
return;
// Translate param: position; type: struct_byref_const
CefGeoposition positionObj;
if (position)
positionObj.Set(*position, false);
// Execute
CefGetGeolocationCallbackCppToC::Get(self)->OnLocationUpdate(
positionObj);
}
// CONSTRUCTOR - Do not edit by hand.
CefGetGeolocationCallbackCppToC::CefGetGeolocationCallbackCppToC(
CefGetGeolocationCallback* cls)
: CefCppToC<CefGetGeolocationCallbackCppToC, CefGetGeolocationCallback,
cef_get_geolocation_callback_t>(cls) {
struct_.struct_.on_location_update =
get_geolocation_callback_on_location_update;
}
#ifndef NDEBUG
template<> long CefCppToC<CefGetGeolocationCallbackCppToC,
CefGetGeolocationCallback, cef_get_geolocation_callback_t>::DebugObjCt =
0;
#endif

View File

@ -0,0 +1,37 @@
// Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
//
// ---------------------------------------------------------------------------
//
// This file was generated by the CEF translator tool. If making changes by
// hand only do so within the body of existing method and function
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
#ifndef CEF_LIBCEF_DLL_CPPTOC_GET_GEOLOCATION_CALLBACK_CPPTOC_H_
#define CEF_LIBCEF_DLL_CPPTOC_GET_GEOLOCATION_CALLBACK_CPPTOC_H_
#pragma once
#ifndef USING_CEF_SHARED
#pragma message("Warning: "__FILE__" may be accessed wrapper-side only")
#else // USING_CEF_SHARED
#include "include/cef_geolocation.h"
#include "include/capi/cef_geolocation_capi.h"
#include "libcef_dll/cpptoc/cpptoc.h"
// Wrap a C++ class with a C structure.
// This class may be instantiated and accessed wrapper-side only.
class CefGetGeolocationCallbackCppToC
: public CefCppToC<CefGetGeolocationCallbackCppToC,
CefGetGeolocationCallback, cef_get_geolocation_callback_t> {
public:
explicit CefGetGeolocationCallbackCppToC(CefGetGeolocationCallback* cls);
virtual ~CefGetGeolocationCallbackCppToC() {}
};
#endif // USING_CEF_SHARED
#endif // CEF_LIBCEF_DLL_CPPTOC_GET_GEOLOCATION_CALLBACK_CPPTOC_H_

View File

@ -0,0 +1,36 @@
// Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
//
// ---------------------------------------------------------------------------
//
// This file was generated by the CEF translator tool. If making changes by
// hand only do so within the body of existing method and function
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
#include "libcef_dll/ctocpp/get_geolocation_callback_ctocpp.h"
// VIRTUAL METHODS - Body may be edited by hand.
void CefGetGeolocationCallbackCToCpp::OnLocationUpdate(
const CefGeoposition& position) {
if (CEF_MEMBER_MISSING(struct_, on_location_update))
return;
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Execute
struct_->on_location_update(struct_,
&position);
}
#ifndef NDEBUG
template<> long CefCToCpp<CefGetGeolocationCallbackCToCpp,
CefGetGeolocationCallback, cef_get_geolocation_callback_t>::DebugObjCt =
0;
#endif

View File

@ -0,0 +1,42 @@
// Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
//
// ---------------------------------------------------------------------------
//
// This file was generated by the CEF translator tool. If making changes by
// hand only do so within the body of existing method and function
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
#ifndef CEF_LIBCEF_DLL_CTOCPP_GET_GEOLOCATION_CALLBACK_CTOCPP_H_
#define CEF_LIBCEF_DLL_CTOCPP_GET_GEOLOCATION_CALLBACK_CTOCPP_H_
#pragma once
#ifndef BUILDING_CEF_SHARED
#pragma message("Warning: "__FILE__" may be accessed DLL-side only")
#else // BUILDING_CEF_SHARED
#include "include/cef_geolocation.h"
#include "include/capi/cef_geolocation_capi.h"
#include "libcef_dll/ctocpp/ctocpp.h"
// Wrap a C structure with a C++ class.
// This class may be instantiated and accessed DLL-side only.
class CefGetGeolocationCallbackCToCpp
: public CefCToCpp<CefGetGeolocationCallbackCToCpp,
CefGetGeolocationCallback, cef_get_geolocation_callback_t> {
public:
explicit CefGetGeolocationCallbackCToCpp(cef_get_geolocation_callback_t* str)
: CefCToCpp<CefGetGeolocationCallbackCToCpp, CefGetGeolocationCallback,
cef_get_geolocation_callback_t>(str) {}
virtual ~CefGetGeolocationCallbackCToCpp() {}
// CefGetGeolocationCallback methods
virtual void OnLocationUpdate(const CefGeoposition& position) OVERRIDE;
};
#endif // BUILDING_CEF_SHARED
#endif // CEF_LIBCEF_DLL_CTOCPP_GET_GEOLOCATION_CALLBACK_CTOCPP_H_

View File

@ -12,6 +12,8 @@
#include "include/cef_app.h"
#include "include/capi/cef_app_capi.h"
#include "include/cef_geolocation.h"
#include "include/capi/cef_geolocation_capi.h"
#include "include/cef_origin_whitelist.h"
#include "include/capi/cef_origin_whitelist_capi.h"
#include "include/cef_path_util.h"
@ -76,6 +78,7 @@
#include "libcef_dll/ctocpp/download_handler_ctocpp.h"
#include "libcef_dll/ctocpp/focus_handler_ctocpp.h"
#include "libcef_dll/ctocpp/geolocation_handler_ctocpp.h"
#include "libcef_dll/ctocpp/get_geolocation_callback_ctocpp.h"
#include "libcef_dll/ctocpp/jsdialog_handler_ctocpp.h"
#include "libcef_dll/ctocpp/keyboard_handler_ctocpp.h"
#include "libcef_dll/ctocpp/life_span_handler_ctocpp.h"
@ -193,6 +196,7 @@ CEF_EXPORT void cef_shutdown() {
DCHECK_EQ(CefFrameCppToC::DebugObjCt, 0);
DCHECK_EQ(CefGeolocationCallbackCppToC::DebugObjCt, 0);
DCHECK_EQ(CefGeolocationHandlerCToCpp::DebugObjCt, 0);
DCHECK_EQ(CefGetGeolocationCallbackCToCpp::DebugObjCt, 0);
DCHECK_EQ(CefJSDialogCallbackCppToC::DebugObjCt, 0);
DCHECK_EQ(CefJSDialogHandlerCToCpp::DebugObjCt, 0);
DCHECK_EQ(CefKeyboardHandlerCToCpp::DebugObjCt, 0);
@ -255,6 +259,23 @@ CEF_EXPORT void cef_quit_message_loop() {
CefQuitMessageLoop();
}
CEF_EXPORT int cef_get_geolocation(
struct _cef_get_geolocation_callback_t* callback) {
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Verify param: callback; type: refptr_diff
DCHECK(callback);
if (!callback)
return 0;
// Execute
bool _retval = CefGetGeolocation(
CefGetGeolocationCallbackCToCpp::Wrap(callback));
// Return type: bool
return _retval;
}
CEF_EXPORT int cef_add_cross_origin_whitelist_entry(
const cef_string_t* source_origin, const cef_string_t* target_protocol,
const cef_string_t* target_domain, int allow_target_subdomains) {

View File

@ -12,6 +12,8 @@
#include "include/cef_app.h"
#include "include/capi/cef_app_capi.h"
#include "include/cef_geolocation.h"
#include "include/capi/cef_geolocation_capi.h"
#include "include/cef_origin_whitelist.h"
#include "include/capi/cef_origin_whitelist_capi.h"
#include "include/cef_path_util.h"
@ -42,6 +44,7 @@
#include "libcef_dll/cpptoc/download_handler_cpptoc.h"
#include "libcef_dll/cpptoc/focus_handler_cpptoc.h"
#include "libcef_dll/cpptoc/geolocation_handler_cpptoc.h"
#include "libcef_dll/cpptoc/get_geolocation_callback_cpptoc.h"
#include "libcef_dll/cpptoc/jsdialog_handler_cpptoc.h"
#include "libcef_dll/cpptoc/keyboard_handler_cpptoc.h"
#include "libcef_dll/cpptoc/life_span_handler_cpptoc.h"
@ -185,6 +188,7 @@ CEF_GLOBAL void CefShutdown() {
DCHECK_EQ(CefFrameCToCpp::DebugObjCt, 0);
DCHECK_EQ(CefGeolocationCallbackCToCpp::DebugObjCt, 0);
DCHECK_EQ(CefGeolocationHandlerCppToC::DebugObjCt, 0);
DCHECK_EQ(CefGetGeolocationCallbackCppToC::DebugObjCt, 0);
DCHECK_EQ(CefJSDialogCallbackCToCpp::DebugObjCt, 0);
DCHECK_EQ(CefJSDialogHandlerCppToC::DebugObjCt, 0);
DCHECK_EQ(CefKeyboardHandlerCppToC::DebugObjCt, 0);
@ -247,6 +251,23 @@ CEF_GLOBAL void CefQuitMessageLoop() {
cef_quit_message_loop();
}
CEF_GLOBAL bool CefGetGeolocation(
CefRefPtr<CefGetGeolocationCallback> callback) {
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Verify param: callback; type: refptr_diff
DCHECK(callback.get());
if (!callback.get())
return false;
// Execute
int _retval = cef_get_geolocation(
CefGetGeolocationCallbackCppToC::Wrap(callback));
// Return type: bool
return _retval?true:false;
}
CEF_GLOBAL bool CefAddCrossOriginWhitelistEntry(const CefString& source_origin,
const CefString& target_protocol, const CefString& target_domain,
bool allow_target_subdomains) {

View File

@ -0,0 +1,204 @@
// Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#include "include/cef_geolocation.h"
#include "include/cef_runnable.h"
#include "tests/unittests/test_handler.h"
#include "tests/unittests/test_util.h"
#include "base/synchronization/waitable_event.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
const char* kTestOrigin = "http://tests/";
const char* kTestUrl = "http://tests/GeolocationTestHandler";
const char* kTestAllowUrl = "http://tests/GeolocationTestHandler.Allow";
const char* kTestDenyUrl = "http://tests/GeolocationTestHandler.Deny";
const char* kTestCancelUrl = "http://tests/GeolocationTestHandler.Cancel";
enum TestMode {
TEST_ALLOW,
TEST_DENY,
TEST_CANCEL,
};
class GeolocationTestHandler : public TestHandler {
public:
GeolocationTestHandler(const TestMode& mode, bool async)
: mode_(mode),
async_(async),
request_id_(-1) {
}
virtual void RunTest() OVERRIDE {
std::string html =
"<html><head><script>"
"navigator.geolocation.getCurrentPosition("
// Success function
"function() {"
"window.location.href = '" + std::string(kTestAllowUrl) + "'; },"
// Error function
"function() {"
"window.location.href = '" + std::string(kTestDenyUrl) + "'; });";
if (mode_ == TEST_CANCEL)
html += "window.location.href = '" + std::string(kTestCancelUrl) + "';";
html += "</script></head><body>TEST START</body></html>";
AddResource(kTestUrl, html, "text/html");
std::string end_html = "<html><body>TEST END</body></html>";
AddResource(kTestAllowUrl, end_html, "text/html");
AddResource(kTestDenyUrl, end_html, "text/html");
AddResource(kTestCancelUrl, end_html, "text/html");
// Create the browser
CreateBrowser(kTestUrl);
}
virtual void OnLoadEnd(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
int httpStatusCode) OVERRIDE {
std::string url = frame->GetURL();
if (url != kTestUrl) {
if (url == kTestAllowUrl)
got_allow_.yes();
else if (url == kTestDenyUrl)
got_deny_.yes();
else if (url == kTestCancelUrl)
got_cancel_.yes();
DestroyTest();
}
}
void ExecuteCallback(CefRefPtr<CefGeolocationCallback> callback) {
if (mode_ == TEST_ALLOW)
callback->Continue(true);
else if (mode_ == TEST_DENY)
callback->Continue(false);
}
virtual void OnRequestGeolocationPermission(
CefRefPtr<CefBrowser> browser,
const CefString& requesting_url,
int request_id,
CefRefPtr<CefGeolocationCallback> callback) OVERRIDE {
got_requestgeolocationpermission_.yes();
EXPECT_TRUE(CefCurrentlyOn(TID_IO));
EXPECT_STREQ(kTestOrigin, requesting_url.ToString().c_str());
request_id_ = request_id;
if (!async_) {
ExecuteCallback(callback);
} else {
CefPostTask(TID_UI,
NewCefRunnableMethod(this, &GeolocationTestHandler::ExecuteCallback,
callback));
}
}
virtual void OnCancelGeolocationPermission(
CefRefPtr<CefBrowser> browser,
const CefString& requesting_url,
int request_id) OVERRIDE {
got_cancelgeolocationpermission_.yes();
EXPECT_TRUE(CefCurrentlyOn(TID_IO));
EXPECT_STREQ(kTestOrigin, requesting_url.ToString().c_str());
EXPECT_EQ(request_id, request_id_);
}
virtual void DestroyTest() OVERRIDE {
EXPECT_TRUE(got_requestgeolocationpermission_);
if (mode_ == TEST_CANCEL)
EXPECT_TRUE(got_cancelgeolocationpermission_);
else
EXPECT_FALSE(got_cancelgeolocationpermission_);
TestHandler::DestroyTest();
}
TestMode mode_;
bool async_;
int request_id_;
TrackCallback got_requestgeolocationpermission_;
TrackCallback got_cancelgeolocationpermission_;
TrackCallback got_allow_;
TrackCallback got_cancel_;
TrackCallback got_deny_;
};
} // namespace
TEST(GeolocationTest, HandlerAllow) {
CefRefPtr<GeolocationTestHandler> handler =
new GeolocationTestHandler(TEST_ALLOW, false);
handler->ExecuteTest();
EXPECT_TRUE(handler->got_allow_);
}
TEST(GeolocationTest, HandlerAllowAsync) {
CefRefPtr<GeolocationTestHandler> handler =
new GeolocationTestHandler(TEST_ALLOW, true);
handler->ExecuteTest();
EXPECT_TRUE(handler->got_allow_);
}
TEST(GeolocationTest, HandlerDeny) {
CefRefPtr<GeolocationTestHandler> handler =
new GeolocationTestHandler(TEST_DENY, false);
handler->ExecuteTest();
EXPECT_TRUE(handler->got_deny_);
}
TEST(GeolocationTest, HandlerDenyAsync) {
CefRefPtr<GeolocationTestHandler> handler =
new GeolocationTestHandler(TEST_DENY, true);
handler->ExecuteTest();
EXPECT_TRUE(handler->got_deny_);
}
TEST(GeolocationTest, HandlerCancel) {
CefRefPtr<GeolocationTestHandler> handler =
new GeolocationTestHandler(TEST_CANCEL, false);
handler->ExecuteTest();
EXPECT_TRUE(handler->got_cancel_);
}
namespace {
class TestGetGeolocationCallback : public CefGetGeolocationCallback {
public:
explicit TestGetGeolocationCallback(base::WaitableEvent* event)
: event_(event) {
}
virtual void OnLocationUpdate(const CefGeoposition& position) OVERRIDE {
EXPECT_TRUE(CefCurrentlyOn(TID_UI));
EXPECT_EQ(position.error_code, GEOPOSITON_ERROR_NONE);
EXPECT_NE(position.latitude, 0.0);
EXPECT_NE(position.longitude, 0.0);
EXPECT_NE(position.accuracy, 0.0);
EXPECT_NE(position.timestamp.year, 0);
event_->Signal();
}
private:
base::WaitableEvent* event_;
IMPLEMENT_REFCOUNTING(TestGetGeolocationCallback);
};
} // namespace
TEST(GeolocationTest, GetGeolocation) {
base::WaitableEvent event(false, false);
CefGetGeolocation(new TestGetGeolocationCallback(&event));
event.Wait();
}

View File

@ -33,6 +33,7 @@ class TrackCallback {
class TestHandler : public CefClient,
public CefDialogHandler,
public CefDisplayHandler,
public CefGeolocationHandler,
public CefJSDialogHandler,
public CefLifeSpanHandler,
public CefLoadHandler,
@ -51,6 +52,9 @@ class TestHandler : public CefClient,
virtual CefRefPtr<CefDisplayHandler> GetDisplayHandler() OVERRIDE {
return this;
}
virtual CefRefPtr<CefGeolocationHandler> GetGeolocationHandler() OVERRIDE {
return this;
}
virtual CefRefPtr<CefJSDialogHandler> GetJSDialogHandler() OVERRIDE {
return this;
}