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/android/testshell/testshell_tab.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/ui/android/window_android_helper.h" 11#include "chrome/common/net/url_fixer_upper.h" 12#include "content/public/browser/android/content_view_core.h" 13#include "content/public/browser/web_contents.h" 14#include "jni/TestShellTab_jni.h" 15#include "ui/android/window_android.h" 16#include "url/gurl.h" 17 18using base::android::ConvertJavaStringToUTF8; 19using base::android::ConvertUTF8ToJavaString; 20using base::android::ScopedJavaLocalRef; 21using chrome::android::ChromeWebContentsDelegateAndroid; 22using content::WebContents; 23using ui::WindowAndroid; 24 25TestShellTab::TestShellTab(JNIEnv* env, 26 jobject obj, 27 WebContents* web_contents, 28 WindowAndroid* window_android) 29 : TabAndroid(env, obj), 30 web_contents_(web_contents) { 31 InitTabHelpers(web_contents); 32 WindowAndroidHelper::FromWebContents(web_contents)-> 33 SetWindowAndroid(window_android); 34} 35 36TestShellTab::~TestShellTab() { 37} 38 39void TestShellTab::Destroy(JNIEnv* env, jobject obj) { 40 delete this; 41} 42 43WebContents* TestShellTab::GetWebContents() { 44 return web_contents_.get(); 45} 46 47browser_sync::SyncedTabDelegate* TestShellTab::GetSyncedTabDelegate() { 48 NOTIMPLEMENTED(); 49 return NULL; 50} 51 52void TestShellTab::OnReceivedHttpAuthRequest(jobject auth_handler, 53 const string16& host, 54 const string16& realm) { 55 NOTIMPLEMENTED(); 56} 57 58void TestShellTab::ShowContextMenu( 59 const content::ContextMenuParams& params) { 60 NOTIMPLEMENTED(); 61} 62 63void TestShellTab::ShowCustomContextMenu( 64 const content::ContextMenuParams& params, 65 const base::Callback<void(int)>& callback) { 66 NOTIMPLEMENTED(); 67} 68 69void TestShellTab::AddShortcutToBookmark( 70 const GURL& url, const string16& title, const SkBitmap& skbitmap, 71 int r_value, int g_value, int b_value) { 72 NOTIMPLEMENTED(); 73} 74 75void TestShellTab::EditBookmark(int64 node_id, bool is_folder) { 76 NOTIMPLEMENTED(); 77} 78 79void TestShellTab::ShowSyncSettings() { 80 NOTIMPLEMENTED(); 81} 82 83void TestShellTab::ShowTermsOfService() { 84 NOTIMPLEMENTED(); 85} 86 87bool TestShellTab::ShouldWelcomePageLinkToTermsOfService() { 88 NOTIMPLEMENTED(); 89 return false; 90} 91 92void TestShellTab::OnNewTabPageReady() { 93 NOTIMPLEMENTED(); 94} 95 96void TestShellTab::RunExternalProtocolDialog(const GURL& url) { 97 NOTIMPLEMENTED(); 98} 99 100bool TestShellTab::RegisterTestShellTab(JNIEnv* env) { 101 return RegisterNativesImpl(env); 102} 103 104void TestShellTab::InitWebContentsDelegate( 105 JNIEnv* env, 106 jobject obj, 107 jobject web_contents_delegate) { 108 web_contents_delegate_.reset( 109 new ChromeWebContentsDelegateAndroid(env, web_contents_delegate)); 110 web_contents_->SetDelegate(web_contents_delegate_.get()); 111} 112 113ScopedJavaLocalRef<jstring> TestShellTab::FixupUrl(JNIEnv* env, 114 jobject obj, 115 jstring url) { 116 GURL fixed_url(URLFixerUpper::FixupURL(ConvertJavaStringToUTF8(env, url), 117 std::string())); 118 119 std::string fixed_spec; 120 if (fixed_url.is_valid()) 121 fixed_spec = fixed_url.spec(); 122 123 return ConvertUTF8ToJavaString(env, fixed_spec); 124} 125 126static jint Init(JNIEnv* env, 127 jobject obj, 128 jint web_contents_ptr, 129 jint window_android_ptr) { 130 TestShellTab* tab = new TestShellTab( 131 env, 132 obj, 133 reinterpret_cast<WebContents*>(web_contents_ptr), 134 reinterpret_cast<WindowAndroid*>(window_android_ptr)); 135 return reinterpret_cast<jint>(tab); 136} 137 138int TestShellTab::GetSyncId() const { 139 NOTIMPLEMENTED(); 140 return 0; 141} 142 143void TestShellTab::SetSyncId(int sync_id) { NOTIMPLEMENTED(); } 144