1 // Copyright 2013 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 "content/shell/browser/shell.h" 6 7 #include <jni.h> 8 9 #include "base/android/jni_string.h" 10 #include "base/android/scoped_java_ref.h" 11 #include "base/command_line.h" 12 #include "base/logging.h" 13 #include "base/strings/string_piece.h" 14 #include "content/public/common/content_switches.h" 15 #include "content/shell/android/shell_manager.h" 16 #include "jni/Shell_jni.h" 17 18 using base::android::AttachCurrentThread; 19 using base::android::ConvertUTF8ToJavaString; 20 21 namespace content { 22 23 void Shell::PlatformInitialize(const gfx::Size& default_window_size) { 24 CommandLine* command_line = CommandLine::ForCurrentProcess(); 25 DCHECK(command_line->HasSwitch(switches::kForceCompositingMode)); 26 DCHECK(command_line->HasSwitch(switches::kEnableThreadedCompositing)); 27 } 28 29 void Shell::PlatformExit() { 30 } 31 32 void Shell::PlatformCleanUp() { 33 } 34 35 void Shell::PlatformEnableUIControl(UIControl control, bool is_enabled) { 36 } 37 38 void Shell::PlatformSetAddressBarURL(const GURL& url) { 39 JNIEnv* env = AttachCurrentThread(); 40 ScopedJavaLocalRef<jstring> j_url = ConvertUTF8ToJavaString(env, url.spec()); 41 Java_Shell_onUpdateUrl(env, java_object_.obj(), j_url.obj()); 42 } 43 44 void Shell::PlatformSetIsLoading(bool loading) { 45 JNIEnv* env = AttachCurrentThread(); 46 Java_Shell_setIsLoading(env, java_object_.obj(), loading); 47 } 48 49 void Shell::PlatformCreateWindow(int width, int height) { 50 java_object_.Reset(AttachCurrentThread(), CreateShellView(this)); 51 } 52 53 void Shell::PlatformSetContents() { 54 JNIEnv* env = AttachCurrentThread(); 55 Java_Shell_initFromNativeTabContents( 56 env, java_object_.obj(), reinterpret_cast<intptr_t>(web_contents())); 57 } 58 59 void Shell::PlatformResizeSubViews() { 60 // Not needed; subviews are bound. 61 } 62 63 void Shell::PlatformSetTitle(const base::string16& title) { 64 NOTIMPLEMENTED(); 65 } 66 67 void Shell::LoadProgressChanged(WebContents* source, double progress) { 68 JNIEnv* env = AttachCurrentThread(); 69 Java_Shell_onLoadProgressChanged(env, java_object_.obj(), progress); 70 } 71 72 void Shell::PlatformToggleFullscreenModeForTab(WebContents* web_contents, 73 bool enter_fullscreen) { 74 JNIEnv* env = AttachCurrentThread(); 75 Java_Shell_toggleFullscreenModeForTab( 76 env, java_object_.obj(), enter_fullscreen); 77 } 78 79 bool Shell::PlatformIsFullscreenForTabOrPending( 80 const WebContents* web_contents) const { 81 JNIEnv* env = AttachCurrentThread(); 82 return Java_Shell_isFullscreenForTabOrPending(env, java_object_.obj()); 83 } 84 85 void Shell::Close() { 86 CloseShellView(java_object_.obj()); 87 java_object_.Reset(); 88 delete this; 89 } 90 91 // static 92 bool Shell::Register(JNIEnv* env) { 93 return RegisterNativesImpl(env); 94 } 95 96 } // namespace content 97