blob: c61a333f1cc3d85bd4a27b67a46bc3c11a084e5f [file] [log] [blame]
[email protected]de7d61ff2013-08-20 11:30:411// Copyright 2013 The Chromium Authors. All rights reserved.
[email protected]a08029b42012-04-25 03:18:462// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]de7d61ff2013-08-20 11:30:415#include "content/shell/browser/shell.h"
[email protected]a08029b42012-04-25 03:18:466
[email protected]82e9e2b12012-07-19 00:32:017#include <jni.h>
8
[email protected]82e9e2b12012-07-19 00:32:019#include "base/android/jni_string.h"
[email protected]b9e7c479f2013-04-12 04:33:2410#include "base/android/scoped_java_ref.h"
[email protected]15c0ba42012-08-01 00:16:4611#include "base/command_line.h"
[email protected]a08029b42012-04-25 03:18:4612#include "base/logging.h"
[email protected]b9e7c479f2013-04-12 04:33:2413#include "base/strings/string_piece.h"
dtrainor25ee0c32015-01-27 20:15:5314#include "content/public/browser/web_contents.h"
[email protected]15c0ba42012-08-01 00:16:4615#include "content/public/common/content_switches.h"
[email protected]a08029b42012-04-25 03:18:4616#include "content/shell/android/shell_manager.h"
[email protected]e46f66152012-07-19 20:02:5517#include "jni/Shell_jni.h"
[email protected]82e9e2b12012-07-19 00:32:0118
19using base::android::AttachCurrentThread;
20using base::android::ConvertUTF8ToJavaString;
torne86560112016-08-04 15:59:0421using base::android::JavaParamRef;
22using base::android::ScopedJavaLocalRef;
[email protected]a08029b42012-04-25 03:18:4623
24namespace content {
25
[email protected]6153b272013-01-25 22:29:2326void Shell::PlatformInitialize(const gfx::Size& default_window_size) {
[email protected]a08029b42012-04-25 03:18:4627}
28
[email protected]4249a422013-11-27 19:04:0429void Shell::PlatformExit() {
30}
31
[email protected]a08029b42012-04-25 03:18:4632void Shell::PlatformCleanUp() {
[email protected]fee3a782014-01-25 07:58:3333 JNIEnv* env = AttachCurrentThread();
34 if (java_object_.is_null())
35 return;
torne948f3662016-08-16 15:10:4436 Java_Shell_onNativeDestroyed(env, java_object_);
[email protected]a08029b42012-04-25 03:18:4637}
38
39void Shell::PlatformEnableUIControl(UIControl control, bool is_enabled) {
[email protected]1b3aed22014-05-22 19:57:1140 JNIEnv* env = AttachCurrentThread();
41 if (java_object_.is_null())
42 return;
torne948f3662016-08-16 15:10:4443 Java_Shell_enableUiControl(env, java_object_, control, is_enabled);
[email protected]a08029b42012-04-25 03:18:4644}
45
46void Shell::PlatformSetAddressBarURL(const GURL& url) {
[email protected]82e9e2b12012-07-19 00:32:0147 JNIEnv* env = AttachCurrentThread();
[email protected]48224a72012-11-10 03:49:1148 ScopedJavaLocalRef<jstring> j_url = ConvertUTF8ToJavaString(env, url.spec());
torne948f3662016-08-16 15:10:4449 Java_Shell_onUpdateUrl(env, java_object_, j_url);
[email protected]a08029b42012-04-25 03:18:4650}
51
52void Shell::PlatformSetIsLoading(bool loading) {
[email protected]6a5fcf6f2012-09-29 14:18:4053 JNIEnv* env = AttachCurrentThread();
torne948f3662016-08-16 15:10:4454 Java_Shell_setIsLoading(env, java_object_, loading);
[email protected]a08029b42012-04-25 03:18:4655}
56
57void Shell::PlatformCreateWindow(int width, int height) {
torneb105fe32015-08-27 16:57:4458 java_object_.Reset(CreateShellView(this));
[email protected]a08029b42012-04-25 03:18:4659}
60
61void Shell::PlatformSetContents() {
[email protected]82e9e2b12012-07-19 00:32:0162 JNIEnv* env = AttachCurrentThread();
torne948f3662016-08-16 15:10:4463 Java_Shell_initFromNativeTabContents(env, java_object_,
64 web_contents()->GetJavaWebContents());
[email protected]a08029b42012-04-25 03:18:4665}
66
67void Shell::PlatformResizeSubViews() {
68 // Not needed; subviews are bound.
69}
70
David Bokan29d3c0b2017-12-20 22:23:2071void Shell::SizeTo(const gfx::Size& content_size) {
72 JNIEnv* env = AttachCurrentThread();
73 Java_Shell_sizeTo(env, java_object_, content_size.width(),
74 content_size.height());
75}
76
[email protected]fcf75d42013-12-03 20:11:2677void Shell::PlatformSetTitle(const base::string16& title) {
xhwang68722de2014-10-02 01:15:0778 NOTIMPLEMENTED() << ": " << title;
[email protected]aecc085b2012-06-01 18:15:5379}
80
[email protected]dbe9e952012-09-11 00:59:2981void Shell::LoadProgressChanged(WebContents* source, double progress) {
[email protected]82e9e2b12012-07-19 00:32:0182 JNIEnv* env = AttachCurrentThread();
torne948f3662016-08-16 15:10:4483 Java_Shell_onLoadProgressChanged(env, java_object_, progress);
[email protected]82e9e2b12012-07-19 00:32:0184}
85
jinsukkim517f9152016-09-29 05:09:2486ScopedJavaLocalRef<jobject> Shell::GetContentVideoViewEmbedder() {
87 JNIEnv* env = base::android::AttachCurrentThread();
88 return Java_Shell_getContentVideoViewEmbedder(env, java_object_);
89}
90
Thomas Guilbert0267a42c2017-08-02 08:08:3391void Shell::SetOverlayMode(bool use_overlay_mode) {
92 JNIEnv* env = base::android::AttachCurrentThread();
93 return Java_Shell_setOverlayMode(env, java_object_, use_overlay_mode);
94}
95
[email protected]99c014c2012-11-27 12:03:4296void Shell::PlatformToggleFullscreenModeForTab(WebContents* web_contents,
97 bool enter_fullscreen) {
[email protected]dc9b45502012-11-22 07:44:1798 JNIEnv* env = AttachCurrentThread();
torne948f3662016-08-16 15:10:4499 Java_Shell_toggleFullscreenModeForTab(env, java_object_, enter_fullscreen);
[email protected]dc9b45502012-11-22 07:44:17100}
101
[email protected]99c014c2012-11-27 12:03:42102bool Shell::PlatformIsFullscreenForTabOrPending(
103 const WebContents* web_contents) const {
[email protected]dc9b45502012-11-22 07:44:17104 JNIEnv* env = AttachCurrentThread();
torne948f3662016-08-16 15:10:44105 return Java_Shell_isFullscreenForTabOrPending(env, java_object_);
[email protected]dc9b45502012-11-22 07:44:17106}
107
[email protected]a08029b42012-04-25 03:18:46108void Shell::Close() {
torne660061cd2016-09-07 17:47:54109 RemoveShellView(java_object_);
[email protected]91c6e312013-05-29 12:41:52110 delete this;
[email protected]a08029b42012-04-25 03:18:46111}
112
[email protected]82e9e2b12012-07-19 00:32:01113// static
Daniel Bratell7aacf952017-11-21 17:51:25114void JNI_Shell_CloseShell(JNIEnv* env,
115 const JavaParamRef<jclass>& clazz,
116 jlong shellPtr) {
[email protected]fee3a782014-01-25 07:58:33117 Shell* shell = reinterpret_cast<Shell*>(shellPtr);
118 shell->Close();
119}
120
[email protected]a08029b42012-04-25 03:18:46121} // namespace content