forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add WebView implementation for CookieManager.
Additional details of the requirements can be found from the Android SDK. http://developer.android.com/reference/android/webkit/CookieManager.html BUG= TEST=make forwarder android_webview_apk android_webview_test_apk Review URL: https://chromiumcodereview.appspot.com/10913074 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@155331 0039d316-1c4b-4281-b951-d872f2087c98
- Loading branch information
tedchoc@chromium.org
committed
Sep 7, 2012
1 parent
99d3005
commit 22c5f08
Showing
22 changed files
with
1,728 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,4 +13,5 @@ include_rules = [ | |
"+chrome/browser/component", | ||
"+content/public", | ||
"+jni", | ||
"+net", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// Copyright (c) 2012 The Chromium 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 "android_webview/browser/aw_cookie_access_policy.h" | ||
|
||
#include "base/logging.h" | ||
#include "base/memory/scoped_ptr.h" | ||
#include "content/public/browser/browser_thread.h" | ||
|
||
using base::AutoLock; | ||
using content::BrowserThread; | ||
|
||
namespace android_webview { | ||
|
||
namespace { | ||
base::LazyInstance<AwCookieAccessPolicy>::Leaky g_lazy_instance; | ||
} // namespace | ||
|
||
AwCookieAccessPolicy::~AwCookieAccessPolicy() { | ||
} | ||
|
||
AwCookieAccessPolicy::AwCookieAccessPolicy() | ||
: allow_access_(false) { | ||
} | ||
|
||
AwCookieAccessPolicy* AwCookieAccessPolicy::GetInstance() { | ||
return g_lazy_instance.Pointer(); | ||
} | ||
|
||
bool AwCookieAccessPolicy::GetGlobalAllowAccess() { | ||
AutoLock lock(lock_); | ||
return allow_access_; | ||
} | ||
|
||
void AwCookieAccessPolicy::SetGlobalAllowAccess(bool allow) { | ||
AutoLock lock(lock_); | ||
allow_access_ = allow; | ||
} | ||
|
||
bool AwCookieAccessPolicy::OnCanGetCookies(const net::URLRequest& request, | ||
const net::CookieList& cookie_list) { | ||
return GetGlobalAllowAccess(); | ||
} | ||
|
||
bool AwCookieAccessPolicy::OnCanSetCookie(const net::URLRequest& request, | ||
const std::string& cookie_line, | ||
net::CookieOptions* options) { | ||
return GetGlobalAllowAccess(); | ||
} | ||
|
||
bool AwCookieAccessPolicy::AllowGetCookie(const GURL& url, | ||
const GURL& first_party, | ||
const net::CookieList& cookie_list, | ||
content::ResourceContext* context, | ||
int render_process_id, | ||
int render_view_id) { | ||
return GetGlobalAllowAccess(); | ||
} | ||
|
||
bool AwCookieAccessPolicy::AllowSetCookie(const GURL& url, | ||
const GURL& first_party, | ||
const std::string& cookie_line, | ||
content::ResourceContext* context, | ||
int render_process_id, | ||
int render_view_id, | ||
net::CookieOptions* options) { | ||
return GetGlobalAllowAccess(); | ||
} | ||
|
||
} // namespace android_webview |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// Copyright (c) 2012 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef ANDROID_WEBVIEW_BROWSER_AW_COOKIE_ACCESS_POLICY_H_ | ||
#define ANDROID_WEBVIEW_BROWSER_AW_COOKIE_ACCESS_POLICY_H_ | ||
|
||
#include "base/basictypes.h" | ||
#include "base/lazy_instance.h" | ||
#include "base/synchronization/lock.h" | ||
#include "net/cookies/canonical_cookie.h" | ||
|
||
namespace content { | ||
class ResourceContext; | ||
} | ||
|
||
namespace net { | ||
class CookieOptions; | ||
class URLRequest; | ||
} | ||
|
||
class GURL; | ||
|
||
namespace android_webview { | ||
|
||
// Manages the cookie access (both setting and getting) policy for WebView. | ||
class AwCookieAccessPolicy { | ||
public: | ||
static AwCookieAccessPolicy* GetInstance(); | ||
|
||
// These manage the global access state shared across requests regardless of | ||
// source (i.e. network or JavaScript). | ||
bool GetGlobalAllowAccess(); | ||
void SetGlobalAllowAccess(bool allow); | ||
|
||
// These are the functions called when operating over cookies from the | ||
// network. See NetworkDelegate for further descriptions. | ||
bool OnCanGetCookies(const net::URLRequest& request, | ||
const net::CookieList& cookie_list); | ||
bool OnCanSetCookie(const net::URLRequest& request, | ||
const std::string& cookie_line, | ||
net::CookieOptions* options); | ||
|
||
// These are the functions called when operating over cookies from the | ||
// renderer. See ContentBrowserClient for further descriptions. | ||
bool AllowGetCookie(const GURL& url, | ||
const GURL& first_party, | ||
const net::CookieList& cookie_list, | ||
content::ResourceContext* context, | ||
int render_process_id, | ||
int render_view_id); | ||
bool AllowSetCookie(const GURL& url, | ||
const GURL& first_party, | ||
const std::string& cookie_line, | ||
content::ResourceContext* context, | ||
int render_process_id, | ||
int render_view_id, | ||
net::CookieOptions* options); | ||
|
||
private: | ||
friend struct base::DefaultLazyInstanceTraits<AwCookieAccessPolicy>; | ||
|
||
AwCookieAccessPolicy(); | ||
~AwCookieAccessPolicy(); | ||
bool allow_access_; | ||
base::Lock lock_; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(AwCookieAccessPolicy); | ||
}; | ||
|
||
} // namespace android_webview | ||
|
||
#endif // ANDROID_WEBVIEW_BROWSER_AW_COOKIE_ACCESS_POLICY_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
// Copyright (c) 2012 The Chromium 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 "android_webview/browser/net/aw_network_delegate.h" | ||
|
||
#include "android_webview/browser/aw_cookie_access_policy.h" | ||
#include "net/base/net_errors.h" | ||
#include "net/base/completion_callback.h" | ||
#include "net/url_request/url_request.h" | ||
|
||
namespace android_webview { | ||
|
||
AwNetworkDelegate::AwNetworkDelegate() { | ||
} | ||
|
||
AwNetworkDelegate::~AwNetworkDelegate() { | ||
} | ||
|
||
int AwNetworkDelegate::OnBeforeURLRequest( | ||
net::URLRequest* request, | ||
const net::CompletionCallback& callback, | ||
GURL* new_url) { | ||
return net::OK; | ||
} | ||
|
||
int AwNetworkDelegate::OnBeforeSendHeaders( | ||
net::URLRequest* request, | ||
const net::CompletionCallback& callback, | ||
net::HttpRequestHeaders* headers) { | ||
return net::OK; | ||
} | ||
|
||
void AwNetworkDelegate::OnSendHeaders(net::URLRequest* request, | ||
const net::HttpRequestHeaders& headers) { | ||
} | ||
|
||
int AwNetworkDelegate::OnHeadersReceived( | ||
net::URLRequest* request, | ||
const net::CompletionCallback& callback, | ||
net::HttpResponseHeaders* original_response_headers, | ||
scoped_refptr<net::HttpResponseHeaders>* override_response_headers) { | ||
return net::OK; | ||
} | ||
|
||
void AwNetworkDelegate::OnBeforeRedirect(net::URLRequest* request, | ||
const GURL& new_location) { | ||
} | ||
|
||
void AwNetworkDelegate::OnResponseStarted(net::URLRequest* request) { | ||
} | ||
|
||
void AwNetworkDelegate::OnRawBytesRead(const net::URLRequest& request, | ||
int bytes_read) { | ||
} | ||
|
||
void AwNetworkDelegate::OnCompleted(net::URLRequest* request, bool started) { | ||
} | ||
|
||
void AwNetworkDelegate::OnURLRequestDestroyed(net::URLRequest* request) { | ||
} | ||
|
||
void AwNetworkDelegate::OnPACScriptError(int line_number, | ||
const string16& error) { | ||
} | ||
|
||
net::NetworkDelegate::AuthRequiredResponse AwNetworkDelegate::OnAuthRequired( | ||
net::URLRequest* request, | ||
const net::AuthChallengeInfo& auth_info, | ||
const AuthCallback& callback, | ||
net::AuthCredentials* credentials) { | ||
return AUTH_REQUIRED_RESPONSE_NO_ACTION; | ||
} | ||
|
||
bool AwNetworkDelegate::OnCanGetCookies(const net::URLRequest& request, | ||
const net::CookieList& cookie_list) { | ||
return AwCookieAccessPolicy::GetInstance()->OnCanGetCookies(request, | ||
cookie_list); | ||
} | ||
|
||
bool AwNetworkDelegate::OnCanSetCookie(const net::URLRequest& request, | ||
const std::string& cookie_line, | ||
net::CookieOptions* options) { | ||
return AwCookieAccessPolicy::GetInstance()->OnCanSetCookie(request, | ||
cookie_line, | ||
options); | ||
} | ||
|
||
bool AwNetworkDelegate::OnCanAccessFile(const net::URLRequest& request, | ||
const FilePath& path) const { | ||
return true; | ||
} | ||
|
||
bool AwNetworkDelegate::OnCanThrottleRequest( | ||
const net::URLRequest& request) const { | ||
return false; | ||
} | ||
|
||
int AwNetworkDelegate::OnBeforeSocketStreamConnect( | ||
net::SocketStream* stream, | ||
const net::CompletionCallback& callback) { | ||
return net::OK; | ||
} | ||
|
||
void AwNetworkDelegate::OnRequestWaitStateChange(const net::URLRequest& request, | ||
RequestWaitState state) { | ||
} | ||
|
||
} // namespace android_webview |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// Copyright (c) 2012 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef ANDROID_WEBVIEW_BROWSER_NET_AW_NETWORK_DELEGATE_H_ | ||
#define ANDROID_WEBVIEW_BROWSER_NET_AW_NETWORK_DELEGATE_H_ | ||
|
||
#include "base/basictypes.h" | ||
#include "net/base/network_delegate.h" | ||
|
||
namespace android_webview { | ||
|
||
// WebView's implementation of the NetworkDelegate. | ||
class AwNetworkDelegate : public net::NetworkDelegate { | ||
public: | ||
AwNetworkDelegate(); | ||
virtual ~AwNetworkDelegate(); | ||
|
||
private: | ||
// NetworkDelegate implementation. | ||
virtual int OnBeforeURLRequest(net::URLRequest* request, | ||
const net::CompletionCallback& callback, | ||
GURL* new_url) OVERRIDE; | ||
virtual int OnBeforeSendHeaders(net::URLRequest* request, | ||
const net::CompletionCallback& callback, | ||
net::HttpRequestHeaders* headers) OVERRIDE; | ||
virtual void OnSendHeaders(net::URLRequest* request, | ||
const net::HttpRequestHeaders& headers) OVERRIDE; | ||
virtual int OnHeadersReceived( | ||
net::URLRequest* request, | ||
const net::CompletionCallback& callback, | ||
net::HttpResponseHeaders* original_response_headers, | ||
scoped_refptr<net::HttpResponseHeaders>* override_response_headers) | ||
OVERRIDE; | ||
virtual void OnBeforeRedirect(net::URLRequest* request, | ||
const GURL& new_location) OVERRIDE; | ||
virtual void OnResponseStarted(net::URLRequest* request) OVERRIDE; | ||
virtual void OnRawBytesRead(const net::URLRequest& request, | ||
int bytes_read) OVERRIDE; | ||
virtual void OnCompleted(net::URLRequest* request, bool started) OVERRIDE; | ||
virtual void OnURLRequestDestroyed(net::URLRequest* request) OVERRIDE; | ||
virtual void OnPACScriptError(int line_number, | ||
const string16& error) OVERRIDE; | ||
virtual net::NetworkDelegate::AuthRequiredResponse OnAuthRequired( | ||
net::URLRequest* request, | ||
const net::AuthChallengeInfo& auth_info, | ||
const AuthCallback& callback, | ||
net::AuthCredentials* credentials) OVERRIDE; | ||
virtual bool OnCanGetCookies(const net::URLRequest& request, | ||
const net::CookieList& cookie_list) OVERRIDE; | ||
virtual bool OnCanSetCookie(const net::URLRequest& request, | ||
const std::string& cookie_line, | ||
net::CookieOptions* options) OVERRIDE; | ||
virtual bool OnCanAccessFile(const net::URLRequest& request, | ||
const FilePath& path) const OVERRIDE; | ||
virtual bool OnCanThrottleRequest( | ||
const net::URLRequest& request) const OVERRIDE; | ||
virtual int OnBeforeSocketStreamConnect( | ||
net::SocketStream* stream, | ||
const net::CompletionCallback& callback) OVERRIDE; | ||
virtual void OnRequestWaitStateChange(const net::URLRequest& request, | ||
RequestWaitState state) OVERRIDE; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(AwNetworkDelegate); | ||
}; | ||
|
||
} // namespace android_webview | ||
|
||
#endif // ANDROID_WEBVIEW_BROWSER_NET_AW_NETWORK_DELEGATE_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.