Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/android/tab_base_android_impl.h" | |
| 6 | |
| 7 #include "base/android/jni_string.h" | |
| 8 #include "base/logging.h" | |
| 9 #include "chrome/browser/android/chrome_web_contents_delegate_android.h" | |
| 10 #include "chrome/browser/net/url_fixer_upper.h" | |
| 11 #include "chrome/browser/ui/tab_contents/tab_contents.h" | |
| 12 #include "content/public/browser/android/content_view_core.h" | |
| 13 #include "content/public/browser/web_contents.h" | |
| 14 #include "googleurl/src/gurl.h" | |
| 15 #include "jni/TabBase_jni.h" | |
| 16 #include "third_party/WebKit/Source/Platform/chromium/public/WebLayer.h" | |
| 17 | |
| 18 using base::android::ConvertJavaStringToUTF8; | |
| 19 using base::android::ConvertUTF8ToJavaString; | |
| 20 using base::android::ScopedJavaLocalRef; | |
| 21 using chrome::android::ChromeWebContentsDelegateAndroid; | |
| 22 using content::WebContents; | |
| 23 | |
| 24 namespace { | |
| 25 class ChromeWebContentsDelegateRenderAndroid | |
| 26 : public ChromeWebContentsDelegateAndroid { | |
| 27 public: | |
| 28 ChromeWebContentsDelegateRenderAndroid(TabBaseAndroidImpl* tab_android_impl, | |
| 29 JNIEnv* env, jobject obj) | |
| 30 : ChromeWebContentsDelegateAndroid(env, obj), | |
| 31 tab_android_impl_(tab_android_impl) { | |
| 32 } | |
| 33 | |
| 34 virtual ~ChromeWebContentsDelegateRenderAndroid() { | |
| 35 } | |
| 36 | |
| 37 virtual void AttachLayer(WebContents* web_contents, | |
| 38 WebKit::WebLayer* layer) OVERRIDE { | |
| 39 tab_android_impl_->tab_layer()->addChild(layer); | |
| 40 } | |
| 41 | |
| 42 virtual void RemoveLayer(WebContents* web_contents, | |
| 43 WebKit::WebLayer* layer) OVERRIDE { | |
| 44 layer->removeFromParent(); | |
| 45 } | |
| 46 private: | |
| 47 TabBaseAndroidImpl* tab_android_impl_; | |
| 48 }; | |
| 49 } // namespace | |
| 50 | |
| 51 TabBaseAndroidImpl::TabBaseAndroidImpl(JNIEnv* env, jobject obj) | |
| 52 : TabAndroid() { | |
| 53 } | |
| 54 | |
| 55 TabBaseAndroidImpl::~TabBaseAndroidImpl() { | |
| 56 } | |
| 57 | |
| 58 void TabBaseAndroidImpl::Destroy(JNIEnv* env, jobject obj) { | |
| 59 delete this; | |
| 60 } | |
| 61 | |
| 62 browser_sync::SyncedTabDelegate* TabBaseAndroidImpl::GetSyncedTabDelegate() { | |
| 63 NOTIMPLEMENTED(); | |
| 64 return NULL; | |
| 65 } | |
| 66 | |
| 67 void TabBaseAndroidImpl::OnReceivedHttpAuthRequest(jobject auth_handler, | |
| 68 const string16& host, | |
| 69 const string16& realm) { | |
| 70 NOTIMPLEMENTED(); | |
| 71 } | |
| 72 | |
| 73 void TabBaseAndroidImpl::ShowContextMenu( | |
| 74 const content::ContextMenuParams& params) { | |
| 75 NOTIMPLEMENTED(); | |
| 76 } | |
| 77 | |
| 78 void TabBaseAndroidImpl::ShowCustomContextMenu( | |
| 79 const content::ContextMenuParams& params, | |
| 80 const base::Callback<void(int)>& callback) { | |
| 81 NOTIMPLEMENTED(); | |
| 82 } | |
| 83 | |
| 84 void TabBaseAndroidImpl::ShowSelectFileDialog( | |
| 85 const base::android::ScopedJavaLocalRef<jobject>& select_file) { | |
| 86 NOTIMPLEMENTED(); | |
| 87 } | |
| 88 | |
| 89 void TabBaseAndroidImpl::AddShortcutToBookmark( | |
| 90 const GURL& url, const string16& title, const SkBitmap& skbitmap, | |
| 91 int r_value, int g_value, int b_value) { | |
| 92 NOTIMPLEMENTED(); | |
| 93 } | |
| 94 | |
| 95 void TabBaseAndroidImpl::RunExternalProtocolDialog(const GURL& url) { | |
| 96 NOTIMPLEMENTED(); | |
| 97 } | |
| 98 | |
| 99 bool TabBaseAndroidImpl::RegisterTabBaseAndroidImpl(JNIEnv* env) { | |
| 100 return RegisterNativesImpl(env); | |
| 101 } | |
| 102 | |
| 103 void TabBaseAndroidImpl::InitTabContents(JNIEnv* env, jobject obj, jobject view, | |
| 104 jobject web_contents_delegate) { | |
| 105 // Build our tab layer. | |
| 106 if (!tab_layer_.get()) | |
| 107 tab_layer_.reset(WebKit::WebLayer::create()); | |
| 108 | |
| 109 content::ContentViewCore* content_view_core = | |
| 110 content::ContentViewCore::GetNativeContentViewCore(env, view); | |
| 111 DCHECK(content_view_core); | |
| 112 // If this is a pop-up, a TabContents may have been created | |
| 113 // in ContentViewClient::AddNewContents(). Check before creating a | |
| 114 // new one. | |
| 115 tab_contents_.reset(InitTabContentsFromView(env, view)); | |
| 116 DCHECK(tab_contents_.get()); | |
| 117 WebContents* web_contents = tab_contents_->web_contents(); | |
| 118 DCHECK(web_contents); | |
| 119 web_contents_delegate_.reset( | |
| 120 new ChromeWebContentsDelegateRenderAndroid(this, | |
| 121 env, | |
| 122 web_contents_delegate)); | |
| 123 web_contents->SetDelegate(web_contents_delegate_.get()); | |
| 124 } | |
| 125 | |
| 126 void TabBaseAndroidImpl::DestroyTabContents(JNIEnv* env, jobject obj) { | |
| 127 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
| |
| 128 WebContents* web_contents = tab_contents_->web_contents(); | |
| 129 DCHECK(web_contents); | |
| 130 web_contents->SetDelegate(NULL); | |
| 131 } | |
| 132 | |
| 133 ScopedJavaLocalRef<jstring> TabBaseAndroidImpl::FixupUrl(JNIEnv* env, | |
| 134 jobject obj, | |
| 135 jstring url) { | |
| 136 GURL fixed_url(URLFixerUpper::FixupURL(ConvertJavaStringToUTF8(env, url), | |
| 137 std::string())); | |
| 138 | |
| 139 std::string fixed_spec; | |
| 140 if (fixed_url.is_valid()) | |
| 141 fixed_spec = fixed_url.spec(); | |
| 142 | |
| 143 return ConvertUTF8ToJavaString(env, fixed_spec); | |
| 144 } | |
| 145 | |
| 146 // ---------------------------------------------------------------------------- | |
| 147 // Native JNI methods | |
| 148 // ---------------------------------------------------------------------------- | |
| 149 | |
| 150 static jint Init(JNIEnv* env, jobject obj) { | |
| 151 TabBaseAndroidImpl* tab = new TabBaseAndroidImpl(env, obj); | |
| 152 return reinterpret_cast<jint>(tab); | |
| 153 } | |
| OLD | NEW |