diff --git a/cef1/cef.gyp b/cef1/cef.gyp index 5b1cc8884..24f680191 100644 --- a/cef1/cef.gyp +++ b/cef1/cef.gyp @@ -302,6 +302,7 @@ 'tests/unittests/content_filter_unittest.cc', 'tests/unittests/cookie_unittest.cc', 'tests/unittests/dom_unittest.cc', + 'tests/unittests/geolocation_unittest.cc', 'tests/unittests/navigation_unittest.cc', 'tests/unittests/request_unittest.cc', 'tests/unittests/run_all_unittests.cc', @@ -724,6 +725,7 @@ 'libcef/external_protocol_handler.h', 'libcef/geolocation_client.cc', 'libcef/geolocation_client.h', + 'libcef/geolocation_impl.cc', 'libcef/http_header_utils.cc', 'libcef/http_header_utils.h', 'libcef/nplugin_impl.cc', diff --git a/cef1/cef_paths.gypi b/cef1/cef_paths.gypi index e06a9acb6..8ec46baed 100644 --- a/cef1/cef_paths.gypi +++ b/cef1/cef_paths.gypi @@ -26,6 +26,7 @@ 'include/cef_find_handler.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', @@ -68,6 +69,7 @@ 'include/capi/cef_find_handler_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', @@ -138,6 +140,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/ctocpp/jsdialog_handler_ctocpp.cc', 'libcef_dll/ctocpp/jsdialog_handler_ctocpp.h', 'libcef_dll/ctocpp/keyboard_handler_ctocpp.cc', @@ -256,6 +260,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/cpptoc/jsdialog_handler_cpptoc.cc', 'libcef_dll/cpptoc/jsdialog_handler_cpptoc.h', 'libcef_dll/cpptoc/keyboard_handler_cpptoc.cc', diff --git a/cef1/include/capi/cef_geolocation_capi.h b/cef1/include/capi/cef_geolocation_capi.h new file mode 100644 index 000000000..c74b0609a --- /dev/null +++ b/cef1/include/capi/cef_geolocation_capi.h @@ -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_ diff --git a/cef1/include/capi/cef_geolocation_handler_capi.h b/cef1/include/capi/cef_geolocation_handler_capi.h index 30eca09a6..1a7b36a91 100644 --- a/cef1/include/capi/cef_geolocation_handler_capi.h +++ b/cef1/include/capi/cef_geolocation_handler_capi.h @@ -66,7 +66,7 @@ typedef struct _cef_geolocation_callback_t { /// // Implement this structure to handle events related to geolocation permission // requests. The functions of this structure will be called on the browser -// process IO thread. +// process UI thread. /// typedef struct _cef_geolocation_handler_t { /// diff --git a/cef1/include/cef_geolocation.h b/cef1/include/cef_geolocation.h new file mode 100644 index 000000000..69c08779c --- /dev/null +++ b/cef1/include/cef_geolocation.h @@ -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 callback); + +#endif // CEF_INCLUDE_CEF_GEOLOCATION_H_ diff --git a/cef1/include/cef_geolocation_handler.h b/cef1/include/cef_geolocation_handler.h index ea92cdd20..4b732b482 100644 --- a/cef1/include/cef_geolocation_handler.h +++ b/cef1/include/cef_geolocation_handler.h @@ -58,7 +58,7 @@ class CefGeolocationCallback : public virtual CefBase { /// // Implement this interface to handle events related to geolocation permission -// requests. The methods of this class will be called on the browser process IO +// requests. The methods of this class will be called on the browser process UI // thread. /// /*--cef(source=client)--*/ diff --git a/cef1/include/internal/cef_types.h b/cef1/include/internal/cef_types.h index b60ca6e42..62c484a8d 100644 --- a/cef1/include/internal/cef_types.h +++ b/cef1/include/internal/cef_types.h @@ -1118,6 +1118,74 @@ typedef struct _cef_proxy_info_t { cef_string_t proxyList; } cef_proxy_info_t; +/// +// 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 diff --git a/cef1/include/internal/cef_types_wrappers.h b/cef1/include/internal/cef_types_wrappers.h index 968c5bfc1..909f5e636 100644 --- a/cef1/include/internal/cef_types_wrappers.h +++ b/cef1/include/internal/cef_types_wrappers.h @@ -640,4 +640,35 @@ class CefProxyInfo : public CefStructBase { 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 CefGeoposition; + #endif // CEF_INCLUDE_INTERNAL_CEF_TYPES_WRAPPERS_H_ diff --git a/cef1/libcef/geolocation_client.cc b/cef1/libcef/geolocation_client.cc index 86e03e75a..c64b85d5d 100644 --- a/cef1/libcef/geolocation_client.cc +++ b/cef1/libcef/geolocation_client.cc @@ -178,7 +178,7 @@ void CefGeolocationClient::requestPermission( DCHECK(CefThread::CurrentlyOn(CefThread::UI)); int bridge_id = pending_permissions_->add(permissionRequest); - string16 origin = permissionRequest.securityOrigin().toString(); + GURL origin = GURL(permissionRequest.securityOrigin().toString()); CefRefPtr client = browser_->GetClient(); if (client.get()) { @@ -188,8 +188,8 @@ void CefGeolocationClient::requestPermission( CefRefPtr callbackPtr( new CefGeolocationCallbackImpl(this, bridge_id)); - handler->OnRequestGeolocationPermission(browser_, origin, bridge_id, - callbackPtr.get()); + handler->OnRequestGeolocationPermission(browser_, origin.spec(), + bridge_id, callbackPtr.get()); return; } } @@ -205,14 +205,16 @@ void CefGeolocationClient::cancelPermissionRequest( int bridge_id; if (!pending_permissions_->remove(permissionRequest, bridge_id)) return; - string16 origin = permissionRequest.securityOrigin().toString(); + GURL origin = GURL(permissionRequest.securityOrigin().toString()); CefRefPtr client = browser_->GetClient(); if (client.get()) { CefRefPtr handler = client->GetGeolocationHandler(); - if (handler.get()) - handler->OnCancelGeolocationPermission(browser_, origin, bridge_id); + if (handler.get()) { + handler->OnCancelGeolocationPermission(browser_, origin.spec(), + bridge_id); + } } } diff --git a/cef1/libcef/geolocation_client.h b/cef1/libcef/geolocation_client.h index 1aea47a7e..85ff5b257 100644 --- a/cef1/libcef/geolocation_client.h +++ b/cef1/libcef/geolocation_client.h @@ -38,16 +38,19 @@ class CefGeolocationClient friend class CefGeolocationCallbackImpl; // WebGeolocationClient methods. - virtual void geolocationDestroyed(); - virtual void startUpdating(); - virtual void stopUpdating(); - virtual void setEnableHighAccuracy(bool enable_high_accuracy); - virtual void setController(WebKit::WebGeolocationController* controller); - virtual bool lastPosition(WebKit::WebGeolocationPosition& position); + virtual void geolocationDestroyed() OVERRIDE; + virtual void startUpdating() OVERRIDE; + virtual void stopUpdating() OVERRIDE; + virtual void setEnableHighAccuracy(bool enable_high_accuracy) OVERRIDE; + virtual void setController( + WebKit::WebGeolocationController* controller) OVERRIDE; + virtual bool lastPosition(WebKit::WebGeolocationPosition& position) OVERRIDE; virtual void requestPermission( - const WebKit::WebGeolocationPermissionRequest& permissionRequest); + const WebKit::WebGeolocationPermissionRequest& permissionRequest) + OVERRIDE; virtual void cancelPermissionRequest( - const WebKit::WebGeolocationPermissionRequest& permissionRequest); + const WebKit::WebGeolocationPermissionRequest& permissionRequest) + OVERRIDE; // Called to continue processing on the IO thread. void OnStartUpdating(bool enable_high_accuracy); diff --git a/cef1/libcef/geolocation_impl.cc b/cef1/libcef/geolocation_impl.cc new file mode 100644 index 000000000..f55d43461 --- /dev/null +++ b/cef1/libcef/geolocation_impl.cc @@ -0,0 +1,80 @@ +// 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/cef_context.h" +#include "libcef/cef_thread.h" +#include "libcef/cef_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 callback, + const content::Geoposition& position) { + if (CefThread::CurrentlyOn(CefThread::UI)) { + CefGeoposition cef_position; + SetPosition(position, cef_position); + callback->OnLocationUpdate(cef_position); + } else { + CefThread::PostTask(CefThread::UI, FROM_HERE, + base::Bind(LocationCallback, callback, position)); + } +} + +} // namespace + +bool CefGetGeolocation(CefRefPtr callback) { + if (!CONTEXT_STATE_VALID()) { + NOTREACHED() << "context not valid"; + return false; + } + + if (!callback.get()) { + NOTREACHED() << "invalid parameter"; + return false; + } + + if (CefThread::CurrentlyOn(CefThread::IO)) { + GeolocationProvider* provider = GeolocationProvider::GetInstance(); + if (provider) { + provider->RequestCallback(base::Bind(LocationCallback, callback)); + return true; + } + return false; + } else { + CefThread::PostTask(CefThread::IO, FROM_HERE, + base::Bind(base::IgnoreResult(CefGetGeolocation), callback)); + return true; + } +} diff --git a/cef1/libcef_dll/cpptoc/get_geolocation_callback_cpptoc.cc b/cef1/libcef_dll/cpptoc/get_geolocation_callback_cpptoc.cc new file mode 100644 index 000000000..5956d241d --- /dev/null +++ b/cef1/libcef_dll/cpptoc/get_geolocation_callback_cpptoc.cc @@ -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(cls) { + struct_.struct_.on_location_update = + get_geolocation_callback_on_location_update; +} + +#ifndef NDEBUG +template<> long CefCppToC::DebugObjCt = + 0; +#endif + diff --git a/cef1/libcef_dll/cpptoc/get_geolocation_callback_cpptoc.h b/cef1/libcef_dll/cpptoc/get_geolocation_callback_cpptoc.h new file mode 100644 index 000000000..b459711b1 --- /dev/null +++ b/cef1/libcef_dll/cpptoc/get_geolocation_callback_cpptoc.h @@ -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 { + public: + explicit CefGetGeolocationCallbackCppToC(CefGetGeolocationCallback* cls); + virtual ~CefGetGeolocationCallbackCppToC() {} +}; + +#endif // USING_CEF_SHARED +#endif // CEF_LIBCEF_DLL_CPPTOC_GET_GEOLOCATION_CALLBACK_CPPTOC_H_ + diff --git a/cef1/libcef_dll/ctocpp/get_geolocation_callback_ctocpp.cc b/cef1/libcef_dll/ctocpp/get_geolocation_callback_ctocpp.cc new file mode 100644 index 000000000..4d5493be1 --- /dev/null +++ b/cef1/libcef_dll/ctocpp/get_geolocation_callback_ctocpp.cc @@ -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::DebugObjCt = + 0; +#endif + diff --git a/cef1/libcef_dll/ctocpp/get_geolocation_callback_ctocpp.h b/cef1/libcef_dll/ctocpp/get_geolocation_callback_ctocpp.h new file mode 100644 index 000000000..e3f3af001 --- /dev/null +++ b/cef1/libcef_dll/ctocpp/get_geolocation_callback_ctocpp.h @@ -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 { + public: + explicit CefGetGeolocationCallbackCToCpp(cef_get_geolocation_callback_t* str) + : CefCToCpp(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_ + diff --git a/cef1/libcef_dll/libcef_dll.cc b/cef1/libcef_dll/libcef_dll.cc index 4a6ffe296..1179f7694 100644 --- a/cef1/libcef_dll/libcef_dll.cc +++ b/cef1/libcef_dll/libcef_dll.cc @@ -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_scheme.h" @@ -59,6 +61,7 @@ #include "libcef_dll/ctocpp/find_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" @@ -134,6 +137,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(CefJSDialogHandlerCToCpp::DebugObjCt, 0); DCHECK_EQ(CefKeyboardHandlerCToCpp::DebugObjCt, 0); DCHECK_EQ(CefLifeSpanHandlerCToCpp::DebugObjCt, 0); @@ -195,6 +199,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) { diff --git a/cef1/libcef_dll/wrapper/libcef_dll_wrapper.cc b/cef1/libcef_dll/wrapper/libcef_dll_wrapper.cc index ab31b7c85..f67dacea7 100644 --- a/cef1/libcef_dll/wrapper/libcef_dll_wrapper.cc +++ b/cef1/libcef_dll/wrapper/libcef_dll_wrapper.cc @@ -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_scheme.h" @@ -36,6 +38,7 @@ #include "libcef_dll/cpptoc/find_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" @@ -136,6 +139,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(CefJSDialogHandlerCppToC::DebugObjCt, 0); DCHECK_EQ(CefKeyboardHandlerCppToC::DebugObjCt, 0); DCHECK_EQ(CefLifeSpanHandlerCppToC::DebugObjCt, 0); @@ -197,6 +201,23 @@ CEF_GLOBAL void CefQuitMessageLoop() { cef_quit_message_loop(); } +CEF_GLOBAL bool CefGetGeolocation( + CefRefPtr 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) { diff --git a/cef1/tests/unittests/geolocation_unittest.cc b/cef1/tests/unittests/geolocation_unittest.cc new file mode 100644 index 000000000..54973bb28 --- /dev/null +++ b/cef1/tests/unittests/geolocation_unittest.cc @@ -0,0 +1,203 @@ +// 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 "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 = + "TEST START"; + AddResource(kTestUrl, html, "text/html"); + + std::string end_html = "TEST END"; + 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 browser, + CefRefPtr 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 callback) { + if (mode_ == TEST_ALLOW) + callback->Continue(true); + else if (mode_ == TEST_DENY) + callback->Continue(false); + } + + virtual void OnRequestGeolocationPermission( + CefRefPtr browser, + const CefString& requesting_url, + int request_id, + CefRefPtr callback) OVERRIDE { + got_requestgeolocationpermission_.yes(); + + EXPECT_TRUE(CefCurrentlyOn(TID_UI)); + + 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 browser, + const CefString& requesting_url, + int request_id) OVERRIDE { + got_cancelgeolocationpermission_.yes(); + + EXPECT_TRUE(CefCurrentlyOn(TID_UI)); + + 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 handler = + new GeolocationTestHandler(TEST_ALLOW, false); + handler->ExecuteTest(); + EXPECT_TRUE(handler->got_allow_); +} + +TEST(GeolocationTest, HandlerAllowAsync) { + CefRefPtr handler = + new GeolocationTestHandler(TEST_ALLOW, true); + handler->ExecuteTest(); + EXPECT_TRUE(handler->got_allow_); +} + +TEST(GeolocationTest, HandlerDeny) { + CefRefPtr handler = + new GeolocationTestHandler(TEST_DENY, false); + handler->ExecuteTest(); + EXPECT_TRUE(handler->got_deny_); +} + +TEST(GeolocationTest, HandlerDenyAsync) { + CefRefPtr handler = + new GeolocationTestHandler(TEST_DENY, true); + handler->ExecuteTest(); + EXPECT_TRUE(handler->got_deny_); +} + +TEST(GeolocationTest, HandlerCancel) { + CefRefPtr 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(); +} diff --git a/cef1/tests/unittests/test_handler.h b/cef1/tests/unittests/test_handler.h index 492b88eae..1dea083a9 100644 --- a/cef1/tests/unittests/test_handler.h +++ b/cef1/tests/unittests/test_handler.h @@ -32,6 +32,7 @@ class TrackCallback { // by test cases. class TestHandler : public CefClient, public CefDisplayHandler, + public CefGeolocationHandler, public CefLifeSpanHandler, public CefLoadHandler, public CefRequestHandler, @@ -48,6 +49,9 @@ class TestHandler : public CefClient, virtual CefRefPtr GetDisplayHandler() OVERRIDE { return this; } + virtual CefRefPtr GetGeolocationHandler() OVERRIDE { + return this; + } virtual CefRefPtr GetLifeSpanHandler() OVERRIDE { return this; }