blob: d78b5f9e87eb261cac02645520b1546b7b967ef6 [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"
Mohamed Heikalc09e1012019-06-21 14:47:2616#include "content/shell/android/content_shell_jni_headers/Shell_jni.h"
[email protected]a08029b42012-04-25 03:18:4617#include "content/shell/android/shell_manager.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
Thomas Guilbert0267a42c2017-08-02 08:08:3382void Shell::SetOverlayMode(bool use_overlay_mode) {
83 JNIEnv* env = base::android::AttachCurrentThread();
84 return Java_Shell_setOverlayMode(env, java_object_, use_overlay_mode);
85}
86
[email protected]99c014c2012-11-27 12:03:4287void Shell::PlatformToggleFullscreenModeForTab(WebContents* web_contents,
88 bool enter_fullscreen) {
[email protected]dc9b45502012-11-22 07:44:1789 JNIEnv* env = AttachCurrentThread();
torne948f3662016-08-16 15:10:4490 Java_Shell_toggleFullscreenModeForTab(env, java_object_, enter_fullscreen);
[email protected]dc9b45502012-11-22 07:44:1791}
92
[email protected]99c014c2012-11-27 12:03:4293bool Shell::PlatformIsFullscreenForTabOrPending(
94 const WebContents* web_contents) const {
[email protected]dc9b45502012-11-22 07:44:1795 JNIEnv* env = AttachCurrentThread();
torne948f3662016-08-16 15:10:4496 return Java_Shell_isFullscreenForTabOrPending(env, java_object_);
[email protected]dc9b45502012-11-22 07:44:1797}
98
Evan Stade9f328112019-10-23 20:49:2599void Shell::LoadProgressChanged(double progress) {
100 JNIEnv* env = AttachCurrentThread();
101 Java_Shell_onLoadProgressChanged(env, java_object_, progress);
102}
103
[email protected]a08029b42012-04-25 03:18:46104void Shell::Close() {
torne660061cd2016-09-07 17:47:54105 RemoveShellView(java_object_);
[email protected]91c6e312013-05-29 12:41:52106 delete this;
[email protected]a08029b42012-04-25 03:18:46107}
108
[email protected]82e9e2b12012-07-19 00:32:01109// static
Daniel Bratell7aacf952017-11-21 17:51:25110void JNI_Shell_CloseShell(JNIEnv* env,
Daniel Bratell7aacf952017-11-21 17:51:25111 jlong shellPtr) {
[email protected]fee3a782014-01-25 07:58:33112 Shell* shell = reinterpret_cast<Shell*>(shellPtr);
113 shell->Close();
114}
115
[email protected]a08029b42012-04-25 03:18:46116} // namespace content