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