Commit 96324809 authored by joth@chromium.org's avatar joth@chromium.org

Support fetching AwContents from a WebContents

This is to allow callbacks coming up from WebContents to find their way back to the java AwContents[Client]


BUG=


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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@153617 0039d316-1c4b-4281-b951-d872f2087c98
parent de105aa6
......@@ -9,6 +9,7 @@
#include "android_webview/native/aw_web_contents_delegate.h"
#include "base/android/jni_android.h"
#include "base/android/jni_string.h"
#include "base/supports_user_data.h"
#include "content/public/browser/android/content_view_core.h"
#include "content/public/browser/web_contents.h"
#include "jni/AwContents_jni.h"
......@@ -20,6 +21,31 @@ using content::WebContents;
namespace android_webview {
namespace {
const void* kAwContentsUserDataKey = &kAwContentsUserDataKey;
class AwContentsUserData : public base::SupportsUserData::Data {
public:
AwContentsUserData(AwContents* ptr) : contents_(ptr) {}
AwContents* get() { return contents_; }
private:
AwContents* contents_;
};
} // namespace
// static
AwContents* AwContents::FromWebContents(content::WebContents* web_contents) {
if (web_contents) {
AwContentsUserData* data = reinterpret_cast<AwContentsUserData*>(
web_contents->GetUserData(kAwContentsUserDataKey));
if (data) return data->get();
}
return NULL;
}
AwContents::AwContents(JNIEnv* env,
jobject obj,
jobject web_contents_delegate,
......@@ -36,9 +62,14 @@ AwContents::AwContents(JNIEnv* env,
web_contents->SetDelegate(web_contents_delegate_.get());
web_contents_delegate_->SetJavaScriptDialogCreator(
dependency_factory->GetJavaScriptDialogCreator());
web_contents->SetUserData(kAwContentsUserDataKey,
new AwContentsUserData(this));
}
AwContents::~AwContents() {
content::WebContents* web_contents = contents_container_->GetWebContents();
DCHECK(AwContents::FromWebContents(web_contents) == this);
web_contents->RemoveUserData(kAwContentsUserDataKey);
}
jint AwContents::GetWebContents(JNIEnv* env, jobject obj) {
......
......@@ -27,12 +27,16 @@ class AwWebContentsDelegate;
// level of indirection provided by the AwContentsContainer abstraction.
class AwContents {
public:
// Returns the AwContents instance associated with |web_contents|, or NULL.
static AwContents* FromWebContents(content::WebContents* web_contents);
AwContents(JNIEnv* env,
jobject obj,
jobject web_contents_delegate,
bool private_browsing);
~AwContents();
// Methods called from Java.
jint GetWebContents(JNIEnv* env, jobject obj);
void Destroy(JNIEnv* env, jobject obj);
......
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