Implementing native chromium GeolocationPermissionContext


BUG=


Review URL: https://chromiumcodereview.appspot.com/11763002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@176032 0039d316-1c4b-4281-b951-d872f2087c98
parent 3b78761f
......@@ -8,8 +8,11 @@
namespace android_webview {
AwBrowserContext::AwBrowserContext(const FilePath path)
: context_storage_path_(path) {
AwBrowserContext::AwBrowserContext(
const FilePath path,
GeolocationPermissionFactoryFn* geolocation_permission_factory)
: context_storage_path_(path),
geolocation_permission_factory_(geolocation_permission_factory) {
}
AwBrowserContext::~AwBrowserContext() {
......@@ -75,10 +78,10 @@ AwBrowserContext::GetDownloadManagerDelegate() {
content::GeolocationPermissionContext*
AwBrowserContext::GetGeolocationPermissionContext() {
// TODO(boliu): Implement this to power WebSettings.setGeolocationEnabled
// setting.
NOTIMPLEMENTED();
return NULL;
if (!geolocation_permission_context_) {
geolocation_permission_context_ = (*geolocation_permission_factory_)();
}
return geolocation_permission_context_;
}
content::SpeechRecognitionPreferences*
......
......@@ -9,14 +9,19 @@
#include "base/file_path.h"
#include "base/memory/ref_counted.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/geolocation_permission_context.h"
namespace android_webview {
class AwURLRequestContextGetter;
typedef content::GeolocationPermissionContext* GeolocationPermissionFactoryFn();
class AwBrowserContext : public content::BrowserContext {
public:
AwBrowserContext(const FilePath path);
AwBrowserContext(
const FilePath path,
GeolocationPermissionFactoryFn* geolocation_permission_factory);
virtual ~AwBrowserContext();
// Called before BrowserThreads are created.
......@@ -51,6 +56,9 @@ class AwBrowserContext : public content::BrowserContext {
FilePath context_storage_path_;
scoped_refptr<AwURLRequestContextGetter> url_request_context_getter_;
GeolocationPermissionFactoryFn* geolocation_permission_factory_;
scoped_refptr<content::GeolocationPermissionContext>
geolocation_permission_context_;
AwDownloadManagerDelegate download_manager_delegate_;
......
......@@ -44,13 +44,15 @@ class DummyAccessTokenStore : public content::AccessTokenStore {
namespace android_webview {
AwContentBrowserClient::AwContentBrowserClient(
ViewDelegateFactoryFn* view_delegate_factory)
ViewDelegateFactoryFn* view_delegate_factory,
GeolocationPermissionFactoryFn* geolocation_permission_factory)
: view_delegate_factory_(view_delegate_factory) {
FilePath user_data_dir;
if (!PathService::Get(base::DIR_ANDROID_APP_DATA, &user_data_dir)) {
NOTREACHED() << "Failed to get app data directory for Android WebView";
}
browser_context_.reset(new AwBrowserContext(user_data_dir));
browser_context_.reset(
new AwBrowserContext(user_data_dir, geolocation_permission_factory));
}
AwContentBrowserClient::~AwContentBrowserClient() {
......
......@@ -17,7 +17,9 @@ class AwContentBrowserClient : public content::ContentBrowserClient {
typedef content::WebContentsViewDelegate* ViewDelegateFactoryFn(
content::WebContents* web_contents);
AwContentBrowserClient(ViewDelegateFactoryFn* view_delegate_factory);
AwContentBrowserClient(
ViewDelegateFactoryFn* view_delegate_factory,
GeolocationPermissionFactoryFn* geolocation_permission_factory);
virtual ~AwContentBrowserClient();
AwBrowserContext* GetAwBrowserContext();
......
......@@ -21,6 +21,7 @@ import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.GeolocationPermissions;
import android.webkit.ValueCallback;
import org.chromium.base.CalledByNative;
......@@ -33,6 +34,7 @@ import org.chromium.content.browser.NavigationHistory;
import org.chromium.content.browser.PageTransitionTypes;
import org.chromium.content.common.CleanupReference;
import org.chromium.content.components.navigation_interception.InterceptNavigationDelegate;
import org.chromium.net.GURLUtils;
import org.chromium.net.X509Util;
import org.chromium.ui.gfx.NativeWindow;
......@@ -840,6 +842,35 @@ public class AwContents {
mContentsClient.onReceivedHttpAuthRequest(handler, host, realm);
}
private static class ChromiumGeolocationCallback implements GeolocationPermissions.Callback {
final int mRenderProcessId;
final int mRenderViewId;
final int mBridgeId;
final String mRequestingFrame;
private ChromiumGeolocationCallback(int renderProcessId, int renderViewId, int bridgeId,
String requestingFrame) {
mRenderProcessId = renderProcessId;
mRenderViewId = renderViewId;
mBridgeId = bridgeId;
mRequestingFrame = requestingFrame;
}
@Override
public void invoke(String origin, boolean allow, boolean retain) {
// TODO(kristianm): Implement callback handling
}
}
@CalledByNative
private void onGeolocationPermissionsShowPrompt(int renderProcessId, int renderViewId,
int bridgeId, String requestingFrame) {
// TODO(kristianm): Check with GeolocationPermissions if origin already has a policy set
mContentsClient.onGeolocationPermissionsShowPrompt(GURLUtils.getOrigin(requestingFrame),
new ChromiumGeolocationCallback(renderProcessId, renderViewId, bridgeId,
requestingFrame));
}
@CalledByNative
public void onFindResultReceived(int activeMatchOrdinal, int numberOfMatches,
boolean isDoneCounting) {
......
......@@ -6,6 +6,7 @@
#include "android_webview/browser/aw_content_browser_client.h"
#include "android_webview/lib/aw_browser_dependency_factory_impl.h"
#include "android_webview/native/aw_geolocation_permission_context.h"
#include "android_webview/native/aw_web_contents_view_delegate.h"
#include "android_webview/renderer/aw_content_renderer_client.h"
#include "base/command_line.h"
......@@ -78,7 +79,9 @@ void AwMainDelegate::ProcessExiting(const std::string& process_type) {
content::ContentBrowserClient*
AwMainDelegate::CreateContentBrowserClient() {
content_browser_client_.reset(
new AwContentBrowserClient(&AwWebContentsViewDelegate::Create));
new AwContentBrowserClient(
&AwWebContentsViewDelegate::Create,
&AwGeolocationPermissionContext::Create));
return content_browser_client_.get();
}
......
......@@ -614,6 +614,22 @@ bool RegisterAwContents(JNIEnv* env) {
return RegisterNativesImpl(env) >= 0;
}
void AwContents::OnGeolocationShowPrompt(int render_process_id,
int render_view_id,
int bridge_id,
const GURL& requesting_frame) {
JNIEnv* env = AttachCurrentThread();
ScopedJavaLocalRef<jstring> j_requesting_frame(
ConvertUTF8ToJavaString(env, requesting_frame.spec()));
Java_AwContents_onGeolocationPermissionsShowPrompt(env,
java_ref_.get(env).obj(), render_process_id, render_view_id, bridge_id,
j_requesting_frame.obj());
}
void AwContents::OnGeolocationHidePrompt() {
// TODO(kristianm): Implement this
}
jint AwContents::FindAllSync(JNIEnv* env, jobject obj, jstring search_string) {
return GetFindHelper()->FindAllSync(
ConvertJavaStringToUTF16(env, search_string));
......
......@@ -102,6 +102,13 @@ class AwContents : public FindHelper::Listener,
int scroll_x, int scroll_y);
void FocusFirstNode(JNIEnv* env, jobject obj);
// Geolocation API support
void OnGeolocationShowPrompt(int render_process_id,
int render_view_id,
int bridge_id,
const GURL& requesting_frame);
void OnGeolocationHidePrompt();
// Find-in-page API and related methods.
jint FindAllSync(JNIEnv* env, jobject obj, jstring search_string);
void FindAllAsync(JNIEnv* env, jobject obj, jstring search_string);
......
// 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/native/aw_geolocation_permission_context.h"
#include "android_webview/native/aw_contents.h"
#include "base/bind.h"
#include "base/callback.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/web_contents.h"
#include "googleurl/src/gurl.h"
namespace android_webview {
AwGeolocationPermissionContext::~AwGeolocationPermissionContext() {
}
void
AwGeolocationPermissionContext::RequestGeolocationPermissionOnUIThread(
int render_process_id,
int render_view_id,
int bridge_id,
const GURL& requesting_frame,
base::Callback<void(bool)> callback) {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
const content::RenderViewHost* host =
content::RenderViewHost::FromID(render_process_id, render_view_id);
content::WebContents* web_contents =
content::WebContents::FromRenderViewHost(host);
AwContents* aw_contents = AwContents::FromWebContents(web_contents);
aw_contents->OnGeolocationShowPrompt(
render_process_id,
render_view_id,
bridge_id,
requesting_frame);
}
void
AwGeolocationPermissionContext::RequestGeolocationPermission(
int render_process_id,
int render_view_id,
int bridge_id,
const GURL& requesting_frame,
base::Callback<void(bool)> callback) {
content::BrowserThread::PostTask(
content::BrowserThread::UI, FROM_HERE,
base::Bind(
&AwGeolocationPermissionContext::
RequestGeolocationPermissionOnUIThread,
this,
render_process_id,
render_view_id,
bridge_id,
requesting_frame,
callback));
}
// static
content::GeolocationPermissionContext*
AwGeolocationPermissionContext::Create() {
return new AwGeolocationPermissionContext();
}
void
AwGeolocationPermissionContext::CancelGeolocationPermissionRequestOnUIThread(
int render_process_id,
int render_view_id,
int bridge_id,
const GURL& requesting_frame) {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
// TODO(kristianm): Implement this
}
void
AwGeolocationPermissionContext::CancelGeolocationPermissionRequest(
int render_process_id,
int render_view_id,
int bridge_id,
const GURL& requesting_frame) {
content::BrowserThread::PostTask(
content::BrowserThread::UI, FROM_HERE,
base::Bind(
&AwGeolocationPermissionContext::
CancelGeolocationPermissionRequestOnUIThread,
this,
render_process_id,
render_view_id,
bridge_id,
requesting_frame));
}
void InvokeCallback(
int render_process_id,
int render_view_id,
int bridge_id,
const GURL& requesting_frame,
bool value) {
// TODO(kristianm): Implement this
}
} // namespace android_webview
// 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_NATIVE_AW_GEOLOCATION_PERMISSION_CONTEXT_H_
#define ANDROID_WEBVIEW_NATIVE_AW_GEOLOCATION_PERMISSION_CONTEXT_H_
#include "base/callback_forward.h"
#include "content/public/browser/geolocation_permission_context.h"
class GURL;
namespace android_webview {
class AwGeolocationPermissionContext :
public content::GeolocationPermissionContext {
public:
static content::GeolocationPermissionContext* Create();
// content::GeolocationPermissionContext implementation
virtual void RequestGeolocationPermission(
int render_process_id,
int render_view_id,
int bridge_id,
const GURL& requesting_frame,
base::Callback<void(bool)> callback) OVERRIDE;
virtual void CancelGeolocationPermissionRequest(
int render_process_id,
int render_view_id,
int bridge_id,
const GURL& requesting_frame) OVERRIDE;
void InvokeCallback(
int render_process_id,
int render_view_id,
int bridge_id,
const GURL& requesting_frame,
bool value);
protected:
virtual ~AwGeolocationPermissionContext();
private:
void RequestGeolocationPermissionOnUIThread(
int render_process_id,
int render_view_id,
int bridge_id,
const GURL& requesting_frame,
base::Callback<void(bool)> callback);
void CancelGeolocationPermissionRequestOnUIThread(
int render_process_id,
int render_view_id,
int bridge_id,
const GURL& requesting_frame);
};
} // namespace android_webview
#endif // ANDROID_WEBVIEW_NATIVE_AW_GEOLOCATION_PERMISSION_CONTEXT_H_
......@@ -32,6 +32,8 @@
'aw_contents.h',
'aw_contents_io_thread_client_impl.cc',
'aw_contents_io_thread_client_impl.h',
'aw_geolocation_permission_context.cc',
'aw_geolocation_permission_context.h',
'aw_http_auth_handler.cc',
'aw_http_auth_handler.h',
'aw_javascript_dialog_creator.cc',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment