Merge branch 'master' of github.com:mapbox/mapbox-gl-native into android-mason
Conflicts: gyp/mbgl-ios.gypi gyp/mbgl-osx.gypi platform/default/asset_request_libuv.cpp src/mbgl/storage/caching_http_file_source.cpp src/mbgl/storage/file_request.cpp src/mbgl/storage/file_request.hpp src/mbgl/storage/file_request_baton.hpp
This commit is contained in:
@@ -169,9 +169,9 @@ The demo applications use Mapbox vector tiles, which **require a Mapbox account
|
||||
|
||||
For iOS and OS X use of the demo apps in Xcode, setup the access token by editing the scheme for the application target, then adding an environment variable with the name `MAPBOX_ACCESS_TOKEN`.
|
||||
|
||||

|
||||

|
||||
|
||||

|
||||

|
||||
|
||||
For Linux, set the environment variable `MAPBOX_ACCESS_TOKEN` to your token.
|
||||
|
||||
|
||||
@@ -39,11 +39,13 @@
|
||||
'../platform/darwin/log_nslog.mm',
|
||||
'../platform/darwin/string_nsstring.mm',
|
||||
'../platform/darwin/http_request_baton_cocoa.mm',
|
||||
'../platform/darwin/application_root.mm',
|
||||
'../platform/darwin/image.mm',
|
||||
'../platform/default/asset_request_baton_noop.cpp',
|
||||
'../platform/default/asset_request_libuv.cpp',
|
||||
],
|
||||
'include_dirs': [
|
||||
'../include',
|
||||
'../src',
|
||||
],
|
||||
'xcode_settings': {
|
||||
'OTHER_CPLUSPLUSFLAGS': [ '<@(uv_cflags)' ],
|
||||
|
||||
@@ -34,7 +34,9 @@
|
||||
'../platform/default/shader_cache_tmp.cpp',
|
||||
'../platform/default/log_stderr.cpp',
|
||||
'../platform/default/string_stdlib.cpp',
|
||||
'../platform/default/asset_request_libuv.cpp',
|
||||
'../platform/default/http_request_baton_curl.cpp',
|
||||
'../platform/default/application_root.cpp',
|
||||
'../platform/default/image.cpp',
|
||||
'../platform/default/image_reader.cpp',
|
||||
'../platform/default/png_reader.cpp',
|
||||
@@ -43,6 +45,7 @@
|
||||
],
|
||||
'include_dirs': [
|
||||
'../include',
|
||||
'../src',
|
||||
],
|
||||
'link_settings': {
|
||||
'libraries': [
|
||||
|
||||
@@ -14,11 +14,13 @@
|
||||
'../platform/darwin/log_nslog.mm',
|
||||
'../platform/darwin/string_nsstring.mm',
|
||||
'../platform/darwin/http_request_baton_cocoa.mm',
|
||||
'../platform/darwin/application_root.mm',
|
||||
'../platform/darwin/image.mm',
|
||||
'../platform/default/asset_request_baton_noop.cpp',
|
||||
'../platform/default/asset_request_libuv.cpp',
|
||||
],
|
||||
'include_dirs': [
|
||||
'../include',
|
||||
'../src',
|
||||
],
|
||||
'xcode_settings': {
|
||||
'OTHER_CPLUSPLUSFLAGS': [ '<@(uv_cflags)' ],
|
||||
|
||||
@@ -18,9 +18,17 @@
|
||||
'type': 'none',
|
||||
'hard_dependency': 1,
|
||||
'dependencies': [ 'touch_styles' ], # required for xcode http://openradar.appspot.com/7232149
|
||||
'direct_dependent_settings': {
|
||||
'mac_bundle_resources': [ '../styles/styles' ],
|
||||
}
|
||||
'conditions': [
|
||||
['OS == "mac"', {
|
||||
'direct_dependent_settings': {
|
||||
'mac_bundle_resources': [ '../styles/styles' ],
|
||||
}
|
||||
}, {
|
||||
'direct_dependent_settings': {
|
||||
'copies': [{ 'files': [ '../styles/styles' ], 'destination': '<(PRODUCT_DIR)' }],
|
||||
}
|
||||
}]
|
||||
],
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -23,6 +23,8 @@ std::string defaultCacheDatabase();
|
||||
// Returns the path to the default shader cache on this system.
|
||||
std::string defaultShaderCache();
|
||||
|
||||
std::string applicationRoot();
|
||||
|
||||
// Shows an alpha image with the specified dimensions in a named window.
|
||||
void show_debug_image(std::string name, const char *data, size_t width, size_t height);
|
||||
|
||||
|
||||
27
include/mbgl/storage/asset_request.hpp
Normal file
27
include/mbgl/storage/asset_request.hpp
Normal file
@@ -0,0 +1,27 @@
|
||||
#ifndef MBGL_STORAGE_ASSET_REQUEST
|
||||
#define MBGL_STORAGE_ASSET_REQUEST
|
||||
|
||||
#include <mbgl/storage/base_request.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
typedef struct uv_loop_s uv_loop_t;
|
||||
|
||||
struct AssetRequestBaton;
|
||||
|
||||
class AssetRequest : public BaseRequest {
|
||||
public:
|
||||
AssetRequest(const std::string &path, uv_loop_t *loop);
|
||||
~AssetRequest();
|
||||
|
||||
void cancel();
|
||||
|
||||
private:
|
||||
AssetRequestBaton *ptr = nullptr;
|
||||
|
||||
friend struct AssetRequestBaton;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
Submodule ios/mapbox-gl-cocoa updated: 1533d3288f...27442b6816
@@ -49,7 +49,7 @@ int main(int argc, char *argv[]) {
|
||||
// handle fullscreen_flag
|
||||
break;
|
||||
case 's':
|
||||
style = std::string("file://") + std::string(optarg);
|
||||
style = std::string("asset://") + std::string(optarg);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -83,7 +83,7 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
// Load style
|
||||
if (style.empty())
|
||||
style = std::string("file://") + uv::cwd() + std::string("/../../styles/styles/bright-v6.json");
|
||||
style = std::string("asset://") + std::string("styles/bright-v6.json");
|
||||
|
||||
map.setStyleURL(style);
|
||||
|
||||
|
||||
@@ -48,6 +48,7 @@
|
||||
'dependencies': [
|
||||
'../mapboxgl.gyp:mbgl-standalone',
|
||||
'../mapboxgl.gyp:mbgl-linux',
|
||||
'../mapboxgl.gyp:bundle_styles',
|
||||
'../mapboxgl.gyp:copy_certificate_bundle',
|
||||
],
|
||||
'copies': [{
|
||||
|
||||
@@ -102,9 +102,7 @@ int main() {
|
||||
if (accessToken) fileSource.setAccessToken([accessToken cStringUsingEncoding:[NSString defaultCStringEncoding]]);
|
||||
|
||||
// Load style
|
||||
const std::string path([[[NSBundle mainBundle] pathForResource:@"bright-v6" ofType:@"json" inDirectory:@"styles/"] UTF8String]);
|
||||
|
||||
map.setStyleURL(std::string("file://") + path);
|
||||
map.setStyleURL("asset://styles/bright-v6.json");
|
||||
|
||||
int ret = view.run();
|
||||
|
||||
|
||||
18
platform/darwin/application_root.mm
Normal file
18
platform/darwin/application_root.mm
Normal file
@@ -0,0 +1,18 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#include <mbgl/platform/platform.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
namespace platform {
|
||||
|
||||
// Returns the path to the default shader cache on this system.
|
||||
std::string applicationRoot() {
|
||||
static const std::string root = []() -> std::string {
|
||||
NSString *path = [[[NSBundle mainBundle] resourceURL] path];
|
||||
return {[path cStringUsingEncoding : NSUTF8StringEncoding],
|
||||
[path lengthOfBytesUsingEncoding:NSUTF8StringEncoding]};
|
||||
}();
|
||||
return root;
|
||||
}
|
||||
}
|
||||
}
|
||||
15
platform/default/application_root.cpp
Normal file
15
platform/default/application_root.cpp
Normal file
@@ -0,0 +1,15 @@
|
||||
#include <mbgl/platform/platform.hpp>
|
||||
|
||||
#include <mbgl/util/uv.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
namespace platform {
|
||||
|
||||
// Returns the path the application root.
|
||||
std::string applicationRoot() {
|
||||
static const std::string root = uv::cwd();
|
||||
return root;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,22 +1,45 @@
|
||||
#include <mbgl/storage/file_request_baton.hpp>
|
||||
#include <mbgl/storage/file_request.hpp>
|
||||
#include <mbgl/storage/asset_request.hpp>
|
||||
#include <mbgl/storage/response.hpp>
|
||||
#include <mbgl/platform/platform.hpp>
|
||||
#include <mbgl/util/std.hpp>
|
||||
|
||||
#include <uv.h>
|
||||
|
||||
#include <limits>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
FileRequestBaton::FileRequestBaton(FileRequest *request_, const std::string &path, uv_loop_t *loop)
|
||||
struct AssetRequestBaton {
|
||||
AssetRequestBaton(AssetRequest *request_, const std::string &path, uv_loop_t *loop);
|
||||
~AssetRequestBaton();
|
||||
|
||||
void cancel();
|
||||
static void fileOpened(uv_fs_t *req);
|
||||
static void fileStated(uv_fs_t *req);
|
||||
static void fileRead(uv_fs_t *req);
|
||||
static void fileClosed(uv_fs_t *req);
|
||||
static void notifyError(uv_fs_t *req);
|
||||
static void cleanup(uv_fs_t *req);
|
||||
|
||||
const std::thread::id threadId;
|
||||
AssetRequest *request = nullptr;
|
||||
uv_fs_t req;
|
||||
uv_file fd = -1;
|
||||
bool canceled = false;
|
||||
std::string body;
|
||||
uv_buf_t buffer;
|
||||
};
|
||||
|
||||
AssetRequestBaton::AssetRequestBaton(AssetRequest *request_, const std::string &path, uv_loop_t *loop)
|
||||
: threadId(std::this_thread::get_id()), request(request_) {
|
||||
req.data = this;
|
||||
uv_fs_open(loop, &req, path.c_str(), O_RDONLY, S_IRUSR, fileOpened);
|
||||
}
|
||||
|
||||
FileRequestBaton::~FileRequestBaton() {
|
||||
AssetRequestBaton::~AssetRequestBaton() {
|
||||
}
|
||||
|
||||
void FileRequestBaton::cancel() {
|
||||
void AssetRequestBaton::cancel() {
|
||||
canceled = true;
|
||||
|
||||
// uv_cancel fails frequently when the request has already been started.
|
||||
@@ -25,8 +48,8 @@ void FileRequestBaton::cancel() {
|
||||
uv_cancel((uv_req_t *)&req);
|
||||
}
|
||||
|
||||
void FileRequestBaton::notifyError(uv_fs_t *req) {
|
||||
FileRequestBaton *ptr = reinterpret_cast<FileRequestBaton *>(req->data);
|
||||
void AssetRequestBaton::notifyError(uv_fs_t *req) {
|
||||
AssetRequestBaton *ptr = reinterpret_cast<AssetRequestBaton *>(req->data);
|
||||
assert(std::this_thread::get_id() == ptr->threadId);
|
||||
|
||||
if (ptr->request && req->result < 0 && !ptr->canceled && req->result != UV_ECANCELED) {
|
||||
@@ -41,8 +64,8 @@ void FileRequestBaton::notifyError(uv_fs_t *req) {
|
||||
}
|
||||
}
|
||||
|
||||
void FileRequestBaton::fileOpened(uv_fs_t *req) {
|
||||
FileRequestBaton *ptr = reinterpret_cast<FileRequestBaton *>(req->data);
|
||||
void AssetRequestBaton::fileOpened(uv_fs_t *req) {
|
||||
AssetRequestBaton *ptr = reinterpret_cast<AssetRequestBaton *>(req->data);
|
||||
assert(std::this_thread::get_id() == ptr->threadId);
|
||||
|
||||
if (req->result < 0) {
|
||||
@@ -56,7 +79,7 @@ void FileRequestBaton::fileOpened(uv_fs_t *req) {
|
||||
uv_fs_req_cleanup(req);
|
||||
|
||||
if (ptr->canceled || !ptr->request) {
|
||||
// Either the FileRequest object has been destructed, or the
|
||||
// Either the AssetRequest object has been destructed, or the
|
||||
// request was canceled.
|
||||
uv_fs_close(req->loop, req, fd, fileClosed);
|
||||
} else {
|
||||
@@ -66,8 +89,8 @@ void FileRequestBaton::fileOpened(uv_fs_t *req) {
|
||||
}
|
||||
}
|
||||
|
||||
void FileRequestBaton::fileStated(uv_fs_t *req) {
|
||||
FileRequestBaton *ptr = reinterpret_cast<FileRequestBaton *>(req->data);
|
||||
void AssetRequestBaton::fileStated(uv_fs_t *req) {
|
||||
AssetRequestBaton *ptr = reinterpret_cast<AssetRequestBaton *>(req->data);
|
||||
assert(std::this_thread::get_id() == ptr->threadId);
|
||||
|
||||
if (req->result != 0 || ptr->canceled || !ptr->request) {
|
||||
@@ -113,8 +136,8 @@ void FileRequestBaton::fileStated(uv_fs_t *req) {
|
||||
}
|
||||
}
|
||||
|
||||
void FileRequestBaton::fileRead(uv_fs_t *req) {
|
||||
FileRequestBaton *ptr = reinterpret_cast<FileRequestBaton *>(req->data);
|
||||
void AssetRequestBaton::fileRead(uv_fs_t *req) {
|
||||
AssetRequestBaton *ptr = reinterpret_cast<AssetRequestBaton *>(req->data);
|
||||
assert(std::this_thread::get_id() == ptr->threadId);
|
||||
|
||||
if (req->result < 0 || ptr->canceled || !ptr->request) {
|
||||
@@ -135,8 +158,8 @@ void FileRequestBaton::fileRead(uv_fs_t *req) {
|
||||
uv_fs_close(req->loop, req, ptr->fd, fileClosed);
|
||||
}
|
||||
|
||||
void FileRequestBaton::fileClosed(uv_fs_t *req) {
|
||||
assert(std::this_thread::get_id() == reinterpret_cast<FileRequestBaton *>(req->data)->threadId);
|
||||
void AssetRequestBaton::fileClosed(uv_fs_t *req) {
|
||||
assert(std::this_thread::get_id() == (reinterpret_cast<AssetRequestBaton *>(req->data))->threadId);
|
||||
|
||||
if (req->result < 0) {
|
||||
// Closing the file failed. But there isn't anything we can do.
|
||||
@@ -145,8 +168,8 @@ void FileRequestBaton::fileClosed(uv_fs_t *req) {
|
||||
cleanup(req);
|
||||
}
|
||||
|
||||
void FileRequestBaton::cleanup(uv_fs_t *req) {
|
||||
FileRequestBaton *ptr = reinterpret_cast<FileRequestBaton *>(req->data);
|
||||
void AssetRequestBaton::cleanup(uv_fs_t *req) {
|
||||
AssetRequestBaton *ptr = reinterpret_cast<AssetRequestBaton *>(req->data);
|
||||
assert(std::this_thread::get_id() == ptr->threadId);
|
||||
|
||||
if (ptr->request) {
|
||||
@@ -158,4 +181,43 @@ void FileRequestBaton::cleanup(uv_fs_t *req) {
|
||||
ptr = nullptr;
|
||||
}
|
||||
|
||||
|
||||
AssetRequest::AssetRequest(const std::string &path_, uv_loop_t *loop)
|
||||
: BaseRequest(path_) {
|
||||
if (!path.empty() && path[0] == '/') {
|
||||
// This is an absolute path. We don't allow this. Note that this is not a way to absolutely
|
||||
// prevent access to resources outside the application bundle; e.g. there could be symlinks
|
||||
// in the application bundle that link to outside. We don't care about these.
|
||||
response = util::make_unique<Response>();
|
||||
response->code = 403;
|
||||
response->message = "Path is outside the application bundle";
|
||||
notify();
|
||||
} else {
|
||||
// Note: The AssetRequestBaton object is deleted in AssetRequestBaton::cleanup().
|
||||
ptr = new AssetRequestBaton(this, platform::applicationRoot() + "/" + path, loop);
|
||||
}
|
||||
}
|
||||
|
||||
void AssetRequest::cancel() {
|
||||
assert(std::this_thread::get_id() == threadId);
|
||||
|
||||
if (ptr) {
|
||||
ptr->cancel();
|
||||
|
||||
// When deleting a AssetRequest object with a uv_fs_* call is in progress, we are making sure
|
||||
// that the callback doesn't accidentally reference this object again.
|
||||
ptr->request = nullptr;
|
||||
ptr = nullptr;
|
||||
}
|
||||
|
||||
notify();
|
||||
}
|
||||
|
||||
AssetRequest::~AssetRequest() {
|
||||
assert(std::this_thread::get_id() == threadId);
|
||||
cancel();
|
||||
|
||||
// Note: The AssetRequestBaton object is deleted in AssetRequestBaton::cleanup().
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
#include <mbgl/storage/caching_http_file_source.hpp>
|
||||
#include <mbgl/storage/file_request.hpp>
|
||||
#include <mbgl/storage/asset_request.hpp>
|
||||
#include <mbgl/storage/http_request.hpp>
|
||||
#include <mbgl/storage/sqlite_store.hpp>
|
||||
#include <mbgl/storage/asset_request.hpp>
|
||||
@@ -18,6 +18,8 @@ CachingHTTPFileSource::~CachingHTTPFileSource() {
|
||||
}
|
||||
|
||||
void CachingHTTPFileSource::setLoop(uv_loop_t* loop_) {
|
||||
assert(!loop);
|
||||
|
||||
threadId = std::this_thread::get_id();
|
||||
store = !path.empty() ? util::ptr<SQLiteStore>(new SQLiteStore(loop_, path)) : nullptr;
|
||||
loop = loop_;
|
||||
@@ -52,6 +54,8 @@ void CachingHTTPFileSource::clearLoop() {
|
||||
}
|
||||
|
||||
store.reset();
|
||||
|
||||
loop = nullptr;
|
||||
}
|
||||
|
||||
void CachingHTTPFileSource::setBase(std::string value) {
|
||||
@@ -96,9 +100,7 @@ std::unique_ptr<Request> CachingHTTPFileSource::request(ResourceType type, const
|
||||
}
|
||||
|
||||
if (!req) {
|
||||
if (url.substr(0, 7) == "file://") {
|
||||
req = std::make_shared<FileRequest>(url.substr(7), loop);
|
||||
} else if (url.substr(0, 8) == "asset://") {
|
||||
if (url.substr(0, 8) == "asset://") {
|
||||
req = std::make_shared<AssetRequest>(url.substr(8), loop);
|
||||
} else {
|
||||
req = std::make_shared<HTTPRequest>(type, url, loop, store);
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
#include <mbgl/storage/file_request.hpp>
|
||||
#include <mbgl/storage/file_request_baton.hpp>
|
||||
#include <mbgl/storage/response.hpp>
|
||||
|
||||
#include <uv.h>
|
||||
|
||||
#include <cassert>
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
FileRequest::FileRequest(const std::string &path_, uv_loop_t *loop)
|
||||
: BaseRequest(path_), ptr(new FileRequestBaton(this, path, loop)) {
|
||||
}
|
||||
|
||||
void FileRequest::cancel() {
|
||||
assert(std::this_thread::get_id() == threadId);
|
||||
|
||||
if (ptr) {
|
||||
ptr->cancel();
|
||||
|
||||
// When deleting a FileRequest object with a uv_fs_* call is in progress, we are making sure
|
||||
// that the callback doesn't accidentally reference this object again.
|
||||
ptr->request = nullptr;
|
||||
ptr = nullptr;
|
||||
}
|
||||
|
||||
notify();
|
||||
}
|
||||
|
||||
FileRequest::~FileRequest() {
|
||||
assert(std::this_thread::get_id() == threadId);
|
||||
cancel();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
#ifndef MBGL_STORAGE_FILE_REQUEST
|
||||
#define MBGL_STORAGE_FILE_REQUEST
|
||||
|
||||
#include <mbgl/storage/base_request.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
typedef struct uv_loop_s uv_loop_t;
|
||||
|
||||
struct FileRequestBaton;
|
||||
|
||||
class FileRequest : public BaseRequest {
|
||||
public:
|
||||
FileRequest(const std::string &path, uv_loop_t *loop);
|
||||
~FileRequest();
|
||||
|
||||
void cancel();
|
||||
|
||||
private:
|
||||
FileRequestBaton *ptr = nullptr;
|
||||
|
||||
friend struct FileRequestBaton;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,36 +0,0 @@
|
||||
#ifndef MBGL_STORAGE_FILE_REQUEST_BATON
|
||||
#define MBGL_STORAGE_FILE_REQUEST_BATON
|
||||
|
||||
#include <mbgl/storage/file_request.hpp>
|
||||
#include <thread>
|
||||
|
||||
#include <uv.h>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
struct FileRequestBaton {
|
||||
FileRequestBaton(FileRequest *request_, const std::string &path, uv_loop_t *loop);
|
||||
~FileRequestBaton();
|
||||
|
||||
void cancel();
|
||||
static void fileOpened(uv_fs_t *req);
|
||||
static void fileStated(uv_fs_t *req);
|
||||
static void fileRead(uv_fs_t *req);
|
||||
static void fileClosed(uv_fs_t *req);
|
||||
static void notifyError(uv_fs_t *req);
|
||||
static void cleanup(uv_fs_t *req);
|
||||
|
||||
const std::thread::id threadId;
|
||||
FileRequest *request = nullptr;
|
||||
uv_fs_t req;
|
||||
uv_file fd = -1;
|
||||
bool canceled = false;
|
||||
std::string body;
|
||||
uv_buf_t buffer;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user