From 0ca9e8ee821826c1a5191de38f755b859033dbb0 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 13 Aug 2014 12:12:43 +0800 Subject: [PATCH 1/3] Add access token store. --- atom.gyp | 2 ++ atom/browser/atom_access_token_store.cc | 29 +++++++++++++++++++++++ atom/browser/atom_access_token_store.h | 31 +++++++++++++++++++++++++ atom/browser/atom_browser_client.cc | 5 ++++ atom/browser/atom_browser_client.h | 1 + 5 files changed, 68 insertions(+) create mode 100644 atom/browser/atom_access_token_store.cc create mode 100644 atom/browser/atom_access_token_store.h diff --git a/atom.gyp b/atom.gyp index e02b70a683ff..47bd744acf30 100644 --- a/atom.gyp +++ b/atom.gyp @@ -83,6 +83,8 @@ 'atom/browser/auto_updater_linux.cc', 'atom/browser/auto_updater_mac.mm', 'atom/browser/auto_updater_win.cc', + 'atom/browser/atom_access_token_store.cc', + 'atom/browser/atom_access_token_store.h', 'atom/browser/atom_browser_client.cc', 'atom/browser/atom_browser_client.h', 'atom/browser/atom_browser_context.cc', diff --git a/atom/browser/atom_access_token_store.cc b/atom/browser/atom_access_token_store.cc new file mode 100644 index 000000000000..0018f77b9430 --- /dev/null +++ b/atom/browser/atom_access_token_store.cc @@ -0,0 +1,29 @@ +// Copyright (c) 2014 GitHub, Inc. All rights reserved. +// Use of this source code is governed by the MIT license that can be +// found in the LICENSE file. + +#include "atom/browser/atom_access_token_store.h" + +#include "atom/browser/atom_browser_context.h" +#include "atom/browser/net/atom_url_request_context_getter.h" + +namespace atom { + +AtomAccessTokenStore::AtomAccessTokenStore() { +} + +AtomAccessTokenStore::~AtomAccessTokenStore() { +} + +void AtomAccessTokenStore::LoadAccessTokens( + const LoadAccessTokensCallbackType& callback) { + AccessTokenSet access_token_set; + callback.Run(access_token_set, + AtomBrowserContext::Get()->url_request_context_getter()); +} + +void AtomAccessTokenStore::SaveAccessToken(const GURL& server_url, + const base::string16& access_token) { +} + +} // namespace atom diff --git a/atom/browser/atom_access_token_store.h b/atom/browser/atom_access_token_store.h new file mode 100644 index 000000000000..4f4f95fb4b36 --- /dev/null +++ b/atom/browser/atom_access_token_store.h @@ -0,0 +1,31 @@ +// Copyright (c) 2014 GitHub, Inc. All rights reserved. +// Use of this source code is governed by the MIT license that can be +// found in the LICENSE file. + +#ifndef ATOM_BROWSER_ATOM_ACCESS_TOKEN_STORE_H_ +#define ATOM_BROWSER_ATOM_ACCESS_TOKEN_STORE_H_ + +#include "content/public/browser/access_token_store.h" + +namespace atom { + +class AtomBrowserContext; + +class AtomAccessTokenStore : public content::AccessTokenStore { + public: + AtomAccessTokenStore(); + virtual ~AtomAccessTokenStore(); + + // content::AccessTokenStore: + virtual void LoadAccessTokens( + const LoadAccessTokensCallbackType& callback) OVERRIDE; + virtual void SaveAccessToken(const GURL& server_url, + const base::string16& access_token) OVERRIDE; + + private: + DISALLOW_COPY_AND_ASSIGN(AtomAccessTokenStore); +}; + +} // namespace atom + +#endif // ATOM_BROWSER_ATOWSER_ATOM_ACCESS_TOKEN_STORE_H_ diff --git a/atom/browser/atom_browser_client.cc b/atom/browser/atom_browser_client.cc index d43b46783ce8..024e8b3d0fca 100644 --- a/atom/browser/atom_browser_client.cc +++ b/atom/browser/atom_browser_client.cc @@ -4,6 +4,7 @@ #include "atom/browser/atom_browser_client.h" +#include "atom/browser/atom_access_token_store.h" #include "atom/browser/atom_browser_context.h" #include "atom/browser/atom_browser_main_parts.h" #include "atom/browser/atom_resource_dispatcher_host_delegate.h" @@ -62,6 +63,10 @@ void AtomBrowserClient::ResourceDispatcherHostCreated() { resource_dispatcher_delegate_.get()); } +content::AccessTokenStore* AtomBrowserClient::CreateAccessTokenStore() { + return new AtomAccessTokenStore; +} + void AtomBrowserClient::OverrideWebkitPrefs( content::RenderViewHost* render_view_host, const GURL& url, diff --git a/atom/browser/atom_browser_client.h b/atom/browser/atom_browser_client.h index afbc895f09eb..1016744ed3d9 100644 --- a/atom/browser/atom_browser_client.h +++ b/atom/browser/atom_browser_client.h @@ -25,6 +25,7 @@ class AtomBrowserClient : public brightray::BrowserClient { content::ProtocolHandlerMap* protocol_handlers, content::ProtocolHandlerScopedVector protocol_interceptors) OVERRIDE; virtual void ResourceDispatcherHostCreated() OVERRIDE; + virtual content::AccessTokenStore* CreateAccessTokenStore() OVERRIDE; virtual void OverrideWebkitPrefs(content::RenderViewHost* render_view_host, const GURL& url, WebPreferences* prefs) OVERRIDE; From adb8fb59bde2fe529dde7c4aca93638a4b4168cf Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 13 Aug 2014 13:28:05 +0800 Subject: [PATCH 2/3] Add network provider for google geolocation api. --- atom/browser/atom_access_token_store.cc | 16 ++++++++++++++++ atom/browser/atom_access_token_store.h | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/atom/browser/atom_access_token_store.cc b/atom/browser/atom_access_token_store.cc index 0018f77b9430..6555ac76aea1 100644 --- a/atom/browser/atom_access_token_store.cc +++ b/atom/browser/atom_access_token_store.cc @@ -7,8 +7,23 @@ #include "atom/browser/atom_browser_context.h" #include "atom/browser/net/atom_url_request_context_getter.h" +#ifndef GOOGLEAPIS_API_KEY +#define GOOGLEAPIS_API_KEY "AIzaSyAQfxPJiounkhOjODEO5ZieffeBv6yft2Q" +#endif + namespace atom { +namespace { + +// Notice that we just combined the api key with the url together here, because +// if we use the standard {url: key} format Chromium would override our key with +// the predefined one in common.gypi of libchromiumcontent, which is empty. +const char* kGeolocationProviderUrl = + "https://www.googleapis.com/geolocation/v1/geolocate?key=" + GOOGLEAPIS_API_KEY; + +} // namespace + AtomAccessTokenStore::AtomAccessTokenStore() { } @@ -18,6 +33,7 @@ AtomAccessTokenStore::~AtomAccessTokenStore() { void AtomAccessTokenStore::LoadAccessTokens( const LoadAccessTokensCallbackType& callback) { AccessTokenSet access_token_set; + access_token_set[GURL(kGeolocationProviderUrl)]; callback.Run(access_token_set, AtomBrowserContext::Get()->url_request_context_getter()); } diff --git a/atom/browser/atom_access_token_store.h b/atom/browser/atom_access_token_store.h index 4f4f95fb4b36..d1d080ac33a0 100644 --- a/atom/browser/atom_access_token_store.h +++ b/atom/browser/atom_access_token_store.h @@ -28,4 +28,4 @@ class AtomAccessTokenStore : public content::AccessTokenStore { } // namespace atom -#endif // ATOM_BROWSER_ATOWSER_ATOM_ACCESS_TOKEN_STORE_H_ +#endif // ATOM_BROWSER_ATOM_ACCESS_TOKEN_STORE_H_ From 8a7efcdcd2b565d2f03a45a79d0563f7b3ab7f8e Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 13 Aug 2014 14:43:21 +0800 Subject: [PATCH 3/3] Fix compilation error on Linux. --- atom/browser/atom_access_token_store.cc | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/atom/browser/atom_access_token_store.cc b/atom/browser/atom_access_token_store.cc index 6555ac76aea1..af0f3c1b27db 100644 --- a/atom/browser/atom_access_token_store.cc +++ b/atom/browser/atom_access_token_store.cc @@ -4,6 +4,8 @@ #include "atom/browser/atom_access_token_store.h" +#include + #include "atom/browser/atom_browser_context.h" #include "atom/browser/net/atom_url_request_context_getter.h" @@ -33,7 +35,14 @@ AtomAccessTokenStore::~AtomAccessTokenStore() { void AtomAccessTokenStore::LoadAccessTokens( const LoadAccessTokensCallbackType& callback) { AccessTokenSet access_token_set; - access_token_set[GURL(kGeolocationProviderUrl)]; + + // Equivelent to access_token_set[kGeolocationProviderUrl]. + // Somehow base::string16 is causing compilation errors when used in a pair + // of std::map on Linux, this can work around it. + std::pair token_pair; + token_pair.first = GURL(kGeolocationProviderUrl); + access_token_set.insert(token_pair); + callback.Run(access_token_set, AtomBrowserContext::Get()->url_request_context_getter()); }