Index: chrome/browser/android/tab_base_android_impl.cc |
diff --git a/chrome/browser/android/tab_base_android_impl.cc b/chrome/browser/android/tab_base_android_impl.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..2e0baf6814d785e823b80280dfa78b7710a17f4b |
--- /dev/null |
+++ b/chrome/browser/android/tab_base_android_impl.cc |
@@ -0,0 +1,153 @@ |
+// 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 "chrome/browser/android/tab_base_android_impl.h" |
+ |
+#include "base/android/jni_string.h" |
+#include "base/logging.h" |
+#include "chrome/browser/android/chrome_web_contents_delegate_android.h" |
+#include "chrome/browser/net/url_fixer_upper.h" |
+#include "chrome/browser/ui/tab_contents/tab_contents.h" |
+#include "content/public/browser/android/content_view_core.h" |
+#include "content/public/browser/web_contents.h" |
+#include "googleurl/src/gurl.h" |
+#include "jni/TabBase_jni.h" |
+#include "third_party/WebKit/Source/Platform/chromium/public/WebLayer.h" |
+ |
+using base::android::ConvertJavaStringToUTF8; |
+using base::android::ConvertUTF8ToJavaString; |
+using base::android::ScopedJavaLocalRef; |
+using chrome::android::ChromeWebContentsDelegateAndroid; |
+using content::WebContents; |
+ |
+namespace { |
+class ChromeWebContentsDelegateRenderAndroid |
+ : public ChromeWebContentsDelegateAndroid { |
+ public: |
+ ChromeWebContentsDelegateRenderAndroid(TabBaseAndroidImpl* tab_android_impl, |
+ JNIEnv* env, jobject obj) |
+ : ChromeWebContentsDelegateAndroid(env, obj), |
+ tab_android_impl_(tab_android_impl) { |
+ } |
+ |
+ virtual ~ChromeWebContentsDelegateRenderAndroid() { |
+ } |
+ |
+ virtual void AttachLayer(WebContents* web_contents, |
+ WebKit::WebLayer* layer) OVERRIDE { |
+ tab_android_impl_->tab_layer()->addChild(layer); |
+ } |
+ |
+ virtual void RemoveLayer(WebContents* web_contents, |
+ WebKit::WebLayer* layer) OVERRIDE { |
+ layer->removeFromParent(); |
+ } |
+ private: |
+ TabBaseAndroidImpl* tab_android_impl_; |
+}; |
+} // namespace |
+ |
+TabBaseAndroidImpl::TabBaseAndroidImpl(JNIEnv* env, jobject obj) |
+ : TabAndroid() { |
+} |
+ |
+TabBaseAndroidImpl::~TabBaseAndroidImpl() { |
+} |
+ |
+void TabBaseAndroidImpl::Destroy(JNIEnv* env, jobject obj) { |
+ delete this; |
+} |
+ |
+browser_sync::SyncedTabDelegate* TabBaseAndroidImpl::GetSyncedTabDelegate() { |
+ NOTIMPLEMENTED(); |
+ return NULL; |
+} |
+ |
+void TabBaseAndroidImpl::OnReceivedHttpAuthRequest(jobject auth_handler, |
+ const string16& host, |
+ const string16& realm) { |
+ NOTIMPLEMENTED(); |
+} |
+ |
+void TabBaseAndroidImpl::ShowContextMenu( |
+ const content::ContextMenuParams& params) { |
+ NOTIMPLEMENTED(); |
+} |
+ |
+void TabBaseAndroidImpl::ShowCustomContextMenu( |
+ const content::ContextMenuParams& params, |
+ const base::Callback<void(int)>& callback) { |
+ NOTIMPLEMENTED(); |
+} |
+ |
+void TabBaseAndroidImpl::ShowSelectFileDialog( |
+ const base::android::ScopedJavaLocalRef<jobject>& select_file) { |
+ NOTIMPLEMENTED(); |
+} |
+ |
+void TabBaseAndroidImpl::AddShortcutToBookmark( |
+ const GURL& url, const string16& title, const SkBitmap& skbitmap, |
+ int r_value, int g_value, int b_value) { |
+ NOTIMPLEMENTED(); |
+} |
+ |
+void TabBaseAndroidImpl::RunExternalProtocolDialog(const GURL& url) { |
+ NOTIMPLEMENTED(); |
+} |
+ |
+bool TabBaseAndroidImpl::RegisterTabBaseAndroidImpl(JNIEnv* env) { |
+ return RegisterNativesImpl(env); |
+} |
+ |
+void TabBaseAndroidImpl::InitTabContents(JNIEnv* env, jobject obj, jobject view, |
+ jobject web_contents_delegate) { |
+ // Build our tab layer. |
+ if (!tab_layer_.get()) |
+ tab_layer_.reset(WebKit::WebLayer::create()); |
+ |
+ content::ContentViewCore* content_view_core = |
+ content::ContentViewCore::GetNativeContentViewCore(env, view); |
+ DCHECK(content_view_core); |
+ // If this is a pop-up, a TabContents may have been created |
+ // in ContentViewClient::AddNewContents(). Check before creating a |
+ // new one. |
+ tab_contents_.reset(InitTabContentsFromView(env, view)); |
+ DCHECK(tab_contents_.get()); |
+ WebContents* web_contents = tab_contents_->web_contents(); |
+ DCHECK(web_contents); |
+ web_contents_delegate_.reset( |
+ new ChromeWebContentsDelegateRenderAndroid(this, |
+ env, |
+ web_contents_delegate)); |
+ web_contents->SetDelegate(web_contents_delegate_.get()); |
+} |
+ |
+void TabBaseAndroidImpl::DestroyTabContents(JNIEnv* env, jobject obj) { |
+ DCHECK(tab_contents_.get()); |
Ted C
2012/09/20 17:23:59
should this also be resetting tab_contents_?
David Trainor- moved to gerrit
2012/09/21 22:59:10
Good catch thanks!
On 2012/09/20 17:23:59, Ted C
|
+ WebContents* web_contents = tab_contents_->web_contents(); |
+ DCHECK(web_contents); |
+ web_contents->SetDelegate(NULL); |
+} |
+ |
+ScopedJavaLocalRef<jstring> TabBaseAndroidImpl::FixupUrl(JNIEnv* env, |
+ jobject obj, |
+ jstring url) { |
+ GURL fixed_url(URLFixerUpper::FixupURL(ConvertJavaStringToUTF8(env, url), |
+ std::string())); |
+ |
+ std::string fixed_spec; |
+ if (fixed_url.is_valid()) |
+ fixed_spec = fixed_url.spec(); |
+ |
+ return ConvertUTF8ToJavaString(env, fixed_spec); |
+} |
+ |
+// ---------------------------------------------------------------------------- |
+// Native JNI methods |
+// ---------------------------------------------------------------------------- |
+ |
+static jint Init(JNIEnv* env, jobject obj) { |
+ TabBaseAndroidImpl* tab = new TabBaseAndroidImpl(env, obj); |
+ return reinterpret_cast<jint>(tab); |
+} |