Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / content / shell / browser / shell_android.cc
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   JNIEnv* env = AttachCurrentThread();
34   if (java_object_.is_null())
35     return;
36   Java_Shell_onNativeDestroyed(env, java_object_.obj());
37 }
38
39 void Shell::PlatformEnableUIControl(UIControl control, bool is_enabled) {
40 }
41
42 void 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
48 void Shell::PlatformSetIsLoading(bool loading) {
49   JNIEnv* env = AttachCurrentThread();
50   Java_Shell_setIsLoading(env, java_object_.obj(), loading);
51 }
52
53 void Shell::PlatformCreateWindow(int width, int height) {
54   java_object_.Reset(AttachCurrentThread(), CreateShellView(this));
55 }
56
57 void Shell::PlatformSetContents() {
58   JNIEnv* env = AttachCurrentThread();
59   Java_Shell_initFromNativeTabContents(
60       env, java_object_.obj(), reinterpret_cast<intptr_t>(web_contents()));
61 }
62
63 void Shell::PlatformResizeSubViews() {
64   // Not needed; subviews are bound.
65 }
66
67 void Shell::PlatformSetTitle(const base::string16& title) {
68   NOTIMPLEMENTED();
69 }
70
71 void Shell::LoadProgressChanged(WebContents* source, double progress) {
72   JNIEnv* env = AttachCurrentThread();
73   Java_Shell_onLoadProgressChanged(env, java_object_.obj(), progress);
74 }
75
76 void 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
83 bool Shell::PlatformIsFullscreenForTabOrPending(
84     const WebContents* web_contents) const {
85   JNIEnv* env = AttachCurrentThread();
86   return Java_Shell_isFullscreenForTabOrPending(env, java_object_.obj());
87 }
88
89 bool Shell::PlatformHandleContextMenu(
90     const content::ContextMenuParams& params) {
91   return false;
92 }
93
94 void Shell::Close() {
95   RemoveShellView(java_object_.obj());
96   delete this;
97 }
98
99 // static
100 bool Shell::Register(JNIEnv* env) {
101   return RegisterNativesImpl(env);
102 }
103
104 // static
105 void CloseShell(JNIEnv* env, jclass clazz, jlong shellPtr) {
106   Shell* shell = reinterpret_cast<Shell*>(shellPtr);
107   shell->Close();
108 }
109
110 }  // namespace content