Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1975)

Unified Diff: android_webview/native/aw_contents.cc

Issue 10868095: Support fetching AwContents from a WebContents (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: simpler version Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « android_webview/native/aw_contents.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: android_webview/native/aw_contents.cc
diff --git a/android_webview/native/aw_contents.cc b/android_webview/native/aw_contents.cc
index ce29d18fc0fc12112ced8b2336b290564114bc6b..f5eeebe0f1f166bbfa32331b8327ed4951a9a21a 100644
--- a/android_webview/native/aw_contents.cc
+++ b/android_webview/native/aw_contents.cc
@@ -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) {
« no previous file with comments | « android_webview/native/aw_contents.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698