[email protected] | de7d61ff | 2013-08-20 11:30:41 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors. All rights reserved. |
[email protected] | a08029b4 | 2012-04-25 03:18:46 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | de7d61ff | 2013-08-20 11:30:41 | [diff] [blame] | 5 | #include "content/shell/browser/shell.h" |
[email protected] | a08029b4 | 2012-04-25 03:18:46 | [diff] [blame] | 6 | |
[email protected] | 82e9e2b1 | 2012-07-19 00:32:01 | [diff] [blame] | 7 | #include <jni.h> |
| 8 | |
[email protected] | 82e9e2b1 | 2012-07-19 00:32:01 | [diff] [blame] | 9 | #include "base/android/jni_string.h" |
[email protected] | b9e7c479f | 2013-04-12 04:33:24 | [diff] [blame] | 10 | #include "base/android/scoped_java_ref.h" |
[email protected] | 15c0ba4 | 2012-08-01 00:16:46 | [diff] [blame] | 11 | #include "base/command_line.h" |
[email protected] | a08029b4 | 2012-04-25 03:18:46 | [diff] [blame] | 12 | #include "base/logging.h" |
[email protected] | b9e7c479f | 2013-04-12 04:33:24 | [diff] [blame] | 13 | #include "base/strings/string_piece.h" |
dtrainor | 25ee0c3 | 2015-01-27 20:15:53 | [diff] [blame] | 14 | #include "content/public/browser/web_contents.h" |
[email protected] | 15c0ba4 | 2012-08-01 00:16:46 | [diff] [blame] | 15 | #include "content/public/common/content_switches.h" |
Mohamed Heikal | c09e101 | 2019-06-21 14:47:26 | [diff] [blame] | 16 | #include "content/shell/android/content_shell_jni_headers/Shell_jni.h" |
[email protected] | a08029b4 | 2012-04-25 03:18:46 | [diff] [blame] | 17 | #include "content/shell/android/shell_manager.h" |
[email protected] | 82e9e2b1 | 2012-07-19 00:32:01 | [diff] [blame] | 18 | |
| 19 | using base::android::AttachCurrentThread; |
| 20 | using base::android::ConvertUTF8ToJavaString; |
torne | 8656011 | 2016-08-04 15:59:04 | [diff] [blame] | 21 | using base::android::JavaParamRef; |
| 22 | using base::android::ScopedJavaLocalRef; |
[email protected] | a08029b4 | 2012-04-25 03:18:46 | [diff] [blame] | 23 | |
| 24 | namespace content { |
| 25 | |
[email protected] | 6153b27 | 2013-01-25 22:29:23 | [diff] [blame] | 26 | void Shell::PlatformInitialize(const gfx::Size& default_window_size) { |
[email protected] | a08029b4 | 2012-04-25 03:18:46 | [diff] [blame] | 27 | } |
| 28 | |
[email protected] | 4249a42 | 2013-11-27 19:04:04 | [diff] [blame] | 29 | void Shell::PlatformExit() { |
Eric Karl | f3d07b7 | 2018-06-27 20:07:55 | [diff] [blame] | 30 | DestroyShellManager(); |
[email protected] | 4249a42 | 2013-11-27 19:04:04 | [diff] [blame] | 31 | } |
| 32 | |
[email protected] | a08029b4 | 2012-04-25 03:18:46 | [diff] [blame] | 33 | void Shell::PlatformCleanUp() { |
[email protected] | fee3a78 | 2014-01-25 07:58:33 | [diff] [blame] | 34 | JNIEnv* env = AttachCurrentThread(); |
| 35 | if (java_object_.is_null()) |
| 36 | return; |
torne | 948f366 | 2016-08-16 15:10:44 | [diff] [blame] | 37 | Java_Shell_onNativeDestroyed(env, java_object_); |
[email protected] | a08029b4 | 2012-04-25 03:18:46 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | void Shell::PlatformEnableUIControl(UIControl control, bool is_enabled) { |
[email protected] | 1b3aed2 | 2014-05-22 19:57:11 | [diff] [blame] | 41 | JNIEnv* env = AttachCurrentThread(); |
| 42 | if (java_object_.is_null()) |
| 43 | return; |
torne | 948f366 | 2016-08-16 15:10:44 | [diff] [blame] | 44 | Java_Shell_enableUiControl(env, java_object_, control, is_enabled); |
[email protected] | a08029b4 | 2012-04-25 03:18:46 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | void Shell::PlatformSetAddressBarURL(const GURL& url) { |
[email protected] | 82e9e2b1 | 2012-07-19 00:32:01 | [diff] [blame] | 48 | JNIEnv* env = AttachCurrentThread(); |
[email protected] | 48224a7 | 2012-11-10 03:49:11 | [diff] [blame] | 49 | ScopedJavaLocalRef<jstring> j_url = ConvertUTF8ToJavaString(env, url.spec()); |
torne | 948f366 | 2016-08-16 15:10:44 | [diff] [blame] | 50 | Java_Shell_onUpdateUrl(env, java_object_, j_url); |
[email protected] | a08029b4 | 2012-04-25 03:18:46 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | void Shell::PlatformSetIsLoading(bool loading) { |
[email protected] | 6a5fcf6f | 2012-09-29 14:18:40 | [diff] [blame] | 54 | JNIEnv* env = AttachCurrentThread(); |
torne | 948f366 | 2016-08-16 15:10:44 | [diff] [blame] | 55 | Java_Shell_setIsLoading(env, java_object_, loading); |
[email protected] | a08029b4 | 2012-04-25 03:18:46 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | void Shell::PlatformCreateWindow(int width, int height) { |
torne | b105fe3 | 2015-08-27 16:57:44 | [diff] [blame] | 59 | java_object_.Reset(CreateShellView(this)); |
[email protected] | a08029b4 | 2012-04-25 03:18:46 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | void Shell::PlatformSetContents() { |
[email protected] | 82e9e2b1 | 2012-07-19 00:32:01 | [diff] [blame] | 63 | JNIEnv* env = AttachCurrentThread(); |
torne | 948f366 | 2016-08-16 15:10:44 | [diff] [blame] | 64 | Java_Shell_initFromNativeTabContents(env, java_object_, |
| 65 | web_contents()->GetJavaWebContents()); |
[email protected] | a08029b4 | 2012-04-25 03:18:46 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | void Shell::PlatformResizeSubViews() { |
| 69 | // Not needed; subviews are bound. |
| 70 | } |
| 71 | |
David Bokan | 29d3c0b | 2017-12-20 22:23:20 | [diff] [blame] | 72 | void 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] | fcf75d4 | 2013-12-03 20:11:26 | [diff] [blame] | 78 | void Shell::PlatformSetTitle(const base::string16& title) { |
xhwang | 68722de | 2014-10-02 01:15:07 | [diff] [blame] | 79 | NOTIMPLEMENTED() << ": " << title; |
[email protected] | aecc085b | 2012-06-01 18:15:53 | [diff] [blame] | 80 | } |
| 81 | |
Thomas Guilbert | 0267a42c | 2017-08-02 08:08:33 | [diff] [blame] | 82 | void 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] | 99c014c | 2012-11-27 12:03:42 | [diff] [blame] | 87 | void Shell::PlatformToggleFullscreenModeForTab(WebContents* web_contents, |
| 88 | bool enter_fullscreen) { |
[email protected] | dc9b4550 | 2012-11-22 07:44:17 | [diff] [blame] | 89 | JNIEnv* env = AttachCurrentThread(); |
torne | 948f366 | 2016-08-16 15:10:44 | [diff] [blame] | 90 | Java_Shell_toggleFullscreenModeForTab(env, java_object_, enter_fullscreen); |
[email protected] | dc9b4550 | 2012-11-22 07:44:17 | [diff] [blame] | 91 | } |
| 92 | |
[email protected] | 99c014c | 2012-11-27 12:03:42 | [diff] [blame] | 93 | bool Shell::PlatformIsFullscreenForTabOrPending( |
| 94 | const WebContents* web_contents) const { |
[email protected] | dc9b4550 | 2012-11-22 07:44:17 | [diff] [blame] | 95 | JNIEnv* env = AttachCurrentThread(); |
torne | 948f366 | 2016-08-16 15:10:44 | [diff] [blame] | 96 | return Java_Shell_isFullscreenForTabOrPending(env, java_object_); |
[email protected] | dc9b4550 | 2012-11-22 07:44:17 | [diff] [blame] | 97 | } |
| 98 | |
Evan Stade | 9f32811 | 2019-10-23 20:49:25 | [diff] [blame] | 99 | void Shell::LoadProgressChanged(double progress) { |
| 100 | JNIEnv* env = AttachCurrentThread(); |
| 101 | Java_Shell_onLoadProgressChanged(env, java_object_, progress); |
| 102 | } |
| 103 | |
[email protected] | a08029b4 | 2012-04-25 03:18:46 | [diff] [blame] | 104 | void Shell::Close() { |
torne | 660061cd | 2016-09-07 17:47:54 | [diff] [blame] | 105 | RemoveShellView(java_object_); |
[email protected] | 91c6e31 | 2013-05-29 12:41:52 | [diff] [blame] | 106 | delete this; |
[email protected] | a08029b4 | 2012-04-25 03:18:46 | [diff] [blame] | 107 | } |
| 108 | |
[email protected] | 82e9e2b1 | 2012-07-19 00:32:01 | [diff] [blame] | 109 | // static |
Daniel Bratell | 7aacf95 | 2017-11-21 17:51:25 | [diff] [blame] | 110 | void JNI_Shell_CloseShell(JNIEnv* env, |
Daniel Bratell | 7aacf95 | 2017-11-21 17:51:25 | [diff] [blame] | 111 | jlong shellPtr) { |
[email protected] | fee3a78 | 2014-01-25 07:58:33 | [diff] [blame] | 112 | Shell* shell = reinterpret_cast<Shell*>(shellPtr); |
| 113 | shell->Close(); |
| 114 | } |
| 115 | |
[email protected] | a08029b4 | 2012-04-25 03:18:46 | [diff] [blame] | 116 | } // namespace content |