shell_android.cc revision 5d1f7b1de12d16ceb2c938c56701a3e8bfa558f7
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 18using base::android::AttachCurrentThread; 19using base::android::ConvertUTF8ToJavaString; 20 21namespace content { 22 23void 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 29void Shell::PlatformExit() { 30} 31 32void Shell::PlatformCleanUp() { 33 JNIEnv* env = AttachCurrentThread(); 34 if (java_object_.is_null()) 35 return; 36 Java_Shell_onNativeDestroyed(env, java_object_.obj()); 37} 38 39void Shell::PlatformEnableUIControl(UIControl control, bool is_enabled) { 40} 41 42void Shell::PlatformSetAddressBarURL(const GURL& url) { 43 JNIEnv* env = AttachCurrentThread(); 44 ScopedJavaLocalRef<jstring> j_url = ConvertUTF8ToJavaString(env, url.spec()); 45 Java_Shell_onUpdateUrl(env, java_object_.obj(), j_url.obj()); 46} 47 48void Shell::PlatformSetIsLoading(bool loading) { 49 JNIEnv* env = AttachCurrentThread(); 50 Java_Shell_setIsLoading(env, java_object_.obj(), loading); 51} 52 53void Shell::PlatformCreateWindow(int width, int height) { 54 java_object_.Reset(AttachCurrentThread(), CreateShellView(this)); 55} 56 57void Shell::PlatformSetContents() { 58 JNIEnv* env = AttachCurrentThread(); 59 Java_Shell_initFromNativeTabContents( 60 env, java_object_.obj(), reinterpret_cast<intptr_t>(web_contents())); 61} 62 63void Shell::PlatformResizeSubViews() { 64 // Not needed; subviews are bound. 65} 66 67void Shell::PlatformSetTitle(const base::string16& title) { 68 NOTIMPLEMENTED(); 69} 70 71void Shell::LoadProgressChanged(WebContents* source, double progress) { 72 JNIEnv* env = AttachCurrentThread(); 73 Java_Shell_onLoadProgressChanged(env, java_object_.obj(), progress); 74} 75 76void Shell::PlatformToggleFullscreenModeForTab(WebContents* web_contents, 77 bool enter_fullscreen) { 78 JNIEnv* env = AttachCurrentThread(); 79 Java_Shell_toggleFullscreenModeForTab( 80 env, java_object_.obj(), enter_fullscreen); 81} 82 83bool Shell::PlatformIsFullscreenForTabOrPending( 84 const WebContents* web_contents) const { 85 JNIEnv* env = AttachCurrentThread(); 86 return Java_Shell_isFullscreenForTabOrPending(env, java_object_.obj()); 87} 88 89bool Shell::PlatformHandleContextMenu( 90 const content::ContextMenuParams& params) { 91 return false; 92} 93 94void Shell::Close() { 95 RemoveShellView(java_object_.obj()); 96 delete this; 97} 98 99// static 100bool Shell::Register(JNIEnv* env) { 101 return RegisterNativesImpl(env); 102} 103 104// static 105void CloseShell(JNIEnv* env, jclass clazz, jlong shellPtr) { 106 Shell* shell = reinterpret_cast<Shell*>(shellPtr); 107 shell->Close(); 108} 109 110} // namespace content 111