blob: 3b9bf15870d7a654897bd590576d347f0e7a0d39 [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() {
Eric Karlf3d07b72018-06-27 20:07:5530 DestroyShellManager();
[email protected]4249a422013-11-27 19:04:0431}
32
[email protected]a08029b42012-04-25 03:18:4633void Shell::PlatformCleanUp() {
[email protected]fee3a782014-01-25 07:58:3334 JNIEnv* env = AttachCurrentThread();
35 if (java_object_.is_null())
36 return;
torne948f3662016-08-16 15:10:4437 Java_Shell_onNativeDestroyed(env, java_object_);
[email protected]a08029b42012-04-25 03:18:4638}
39
40void Shell::PlatformEnableUIControl(UIControl control, bool is_enabled) {
[email protected]1b3aed22014-05-22 19:57:1141 JNIEnv* env = AttachCurrentThread();
42 if (java_object_.is_null())
43 return;
torne948f3662016-08-16 15:10:4444 Java_Shell_enableUiControl(env, java_object_, control, is_enabled);
[email protected]a08029b42012-04-25 03:18:4645}
46
47void Shell::PlatformSetAddressBarURL(const GURL& url) {
[email protected]82e9e2b12012-07-19 00:32:0148 JNIEnv* env = AttachCurrentThread();
[email protected]48224a72012-11-10 03:49:1149 ScopedJavaLocalRef<jstring> j_url = ConvertUTF8ToJavaString(env, url.spec());
torne948f3662016-08-16 15:10:4450 Java_Shell_onUpdateUrl(env, java_object_, j_url);
[email protected]a08029b42012-04-25 03:18:4651}
52
53void Shell::PlatformSetIsLoading(bool loading) {
[email protected]6a5fcf6f2012-09-29 14:18:4054 JNIEnv* env = AttachCurrentThread();
torne948f3662016-08-16 15:10:4455 Java_Shell_setIsLoading(env, java_object_, loading);
[email protected]a08029b42012-04-25 03:18:4656}
57
58void Shell::PlatformCreateWindow(int width, int height) {
torneb105fe32015-08-27 16:57:4459 java_object_.Reset(CreateShellView(this));
[email protected]a08029b42012-04-25 03:18:4660}
61
62void Shell::PlatformSetContents() {
[email protected]82e9e2b12012-07-19 00:32:0163 JNIEnv* env = AttachCurrentThread();
torne948f3662016-08-16 15:10:4464 Java_Shell_initFromNativeTabContents(env, java_object_,
65 web_contents()->GetJavaWebContents());
[email protected]a08029b42012-04-25 03:18:4666}
67
68void Shell::PlatformResizeSubViews() {
69 // Not needed; subviews are bound.
70}
71
David Bokan29d3c0b2017-12-20 22:23:2072void Shell::SizeTo(const gfx::Size& content_size) {
73 JNIEnv* env = AttachCurrentThread();
74 Java_Shell_sizeTo(env, java_object_, content_size.width(),
75 content_size.height());
76}
77
[email protected]fcf75d42013-12-03 20:11:2678void Shell::PlatformSetTitle(const base::string16& title) {
xhwang68722de2014-10-02 01:15:0779 NOTIMPLEMENTED() << ": " << title;
[email protected]aecc085b2012-06-01 18:15:5380}
81
[email protected]dbe9e952012-09-11 00:59:2982void Shell::LoadProgressChanged(WebContents* source, double progress) {
[email protected]82e9e2b12012-07-19 00:32:0183 JNIEnv* env = AttachCurrentThread();
torne948f3662016-08-16 15:10:4484 Java_Shell_onLoadProgressChanged(env, java_object_, progress);
[email protected]82e9e2b12012-07-19 00:32:0185}
86
jinsukkim517f9152016-09-29 05:09:2487ScopedJavaLocalRef<jobject> Shell::GetContentVideoViewEmbedder() {
88 JNIEnv* env = base::android::AttachCurrentThread();
89 return Java_Shell_getContentVideoViewEmbedder(env, java_object_);
90}
91
Thomas Guilbert0267a42c2017-08-02 08:08:3392void Shell::SetOverlayMode(bool use_overlay_mode) {
93 JNIEnv* env = base::android::AttachCurrentThread();
94 return Java_Shell_setOverlayMode(env, java_object_, use_overlay_mode);
95}
96
[email protected]99c014c2012-11-27 12:03:4297void Shell::PlatformToggleFullscreenModeForTab(WebContents* web_contents,
98 bool enter_fullscreen) {
[email protected]dc9b45502012-11-22 07:44:1799 JNIEnv* env = AttachCurrentThread();
torne948f3662016-08-16 15:10:44100 Java_Shell_toggleFullscreenModeForTab(env, java_object_, enter_fullscreen);
[email protected]dc9b45502012-11-22 07:44:17101}
102
[email protected]99c014c2012-11-27 12:03:42103bool Shell::PlatformIsFullscreenForTabOrPending(
104 const WebContents* web_contents) const {
[email protected]dc9b45502012-11-22 07:44:17105 JNIEnv* env = AttachCurrentThread();
torne948f3662016-08-16 15:10:44106 return Java_Shell_isFullscreenForTabOrPending(env, java_object_);
[email protected]dc9b45502012-11-22 07:44:17107}
108
[email protected]a08029b42012-04-25 03:18:46109void Shell::Close() {
torne660061cd2016-09-07 17:47:54110 RemoveShellView(java_object_);
[email protected]91c6e312013-05-29 12:41:52111 delete this;
[email protected]a08029b42012-04-25 03:18:46112}
113
[email protected]82e9e2b12012-07-19 00:32:01114// static
Daniel Bratell7aacf952017-11-21 17:51:25115void JNI_Shell_CloseShell(JNIEnv* env,
116 const JavaParamRef<jclass>& clazz,
117 jlong shellPtr) {
[email protected]fee3a782014-01-25 07:58:33118 Shell* shell = reinterpret_cast<Shell*>(shellPtr);
119 shell->Close();
120}
121
[email protected]a08029b42012-04-25 03:18:46122} // namespace content