Skip to content

Commit

Permalink
Add WebView implementation for CookieManager.
Browse files Browse the repository at this point in the history
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
Show file tree
Hide file tree
Showing 22 changed files with 1,728 additions and 6 deletions.
1 change: 1 addition & 0 deletions android_webview/DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ include_rules = [
"+chrome/browser/component",
"+content/public",
"+jni",
"+net",
]
5 changes: 5 additions & 0 deletions android_webview/android_webview.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,14 @@
'common/android_webview_message_generator.h',
'common/render_view_messages.cc',
'common/render_view_messages.h',
'browser/net/aw_network_delegate.cc',
'browser/net/aw_network_delegate.h',
'browser/renderer_host/aw_render_view_host_ext.cc',
'browser/renderer_host/aw_render_view_host_ext.h',
'browser/renderer_host/aw_resource_dispatcher_host_delegate.cc',
'browser/renderer_host/aw_resource_dispatcher_host_delegate.h',
'browser/aw_cookie_access_policy.cc',
'browser/aw_cookie_access_policy.h',
'lib/aw_browser_dependency_factory_impl.cc',
'lib/aw_browser_dependency_factory_impl.h',
'lib/aw_content_browser_client.cc',
Expand Down Expand Up @@ -61,6 +65,7 @@
'<(android_product_out)/obj/lib/libwebview.so',
'<(android_product_out)/system/lib/libwebview.so',
'<(android_product_out)/symbols/system/lib/libwebview.so',
'<(android_product_out)/symbols/data/data/org.chromium.android_webview/lib/libwebview.so',
],
'action': [
'<(install_binary_script)',
Expand Down
71 changes: 71 additions & 0 deletions android_webview/browser/aw_cookie_access_policy.cc
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
73 changes: 73 additions & 0 deletions android_webview/browser/aw_cookie_access_policy.h
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_
109 changes: 109 additions & 0 deletions android_webview/browser/net/aw_network_delegate.cc
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
69 changes: 69 additions & 0 deletions android_webview/browser/net/aw_network_delegate.h
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_
5 changes: 4 additions & 1 deletion android_webview/build/install_binary
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,20 @@

if [ "$3" = "" ]
then
echo "Usage: install_binary path/to/binary path/to/target1 path/to/target2 path/to/symbols"
echo "Usage: install_binary path/to/binary path/to/target1 path/to/target2 path/to/symbols path/to/symbols2"
exit 1
fi

SOURCE=$1
TARGET=$2
TARGET2=$3
SYMBOLS=$4
SYMBOLS2=$5

mkdir -p $(dirname $SYMBOLS)

cp $SOURCE $SYMBOLS
# Create a hard link to avoid the additional copy to the secondary location.
ln $SYMBOLS $SYMBOLS2
$STRIP --strip-unneeded $SOURCE -o $TARGET
cp $TARGET $TARGET2
Loading

0 comments on commit 22c5f08

Please sign in to comment.