[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 | 25ee0c3f | 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" |
[email protected] | a08029b4 | 2012-04-25 03:18:46 | [diff] [blame] | 16 | #include "content/shell/android/shell_manager.h" |
[email protected] | e46f6615 | 2012-07-19 20:02:55 | [diff] [blame] | 17 | #include "jni/Shell_jni.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() { |
| 30 | } |
| 31 | |
[email protected] | a08029b4 | 2012-04-25 03:18:46 | [diff] [blame] | 32 | void Shell::PlatformCleanUp() { |
[email protected] | fee3a78 | 2014-01-25 07:58:33 | [diff] [blame] | 33 | JNIEnv* env = AttachCurrentThread(); |
| 34 | if (java_object_.is_null()) |
| 35 | return; |
| 36 | Java_Shell_onNativeDestroyed(env, java_object_.obj()); |
[email protected] | a08029b4 | 2012-04-25 03:18:46 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | void Shell::PlatformEnableUIControl(UIControl control, bool is_enabled) { |
[email protected] | 1b3aed2 | 2014-05-22 19:57:11 | [diff] [blame] | 40 | JNIEnv* env = AttachCurrentThread(); |
| 41 | if (java_object_.is_null()) |
| 42 | return; |
| 43 | Java_Shell_enableUiControl(env, java_object_.obj(), control, is_enabled); |
[email protected] | a08029b4 | 2012-04-25 03:18:46 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | void Shell::PlatformSetAddressBarURL(const GURL& url) { |
[email protected] | 82e9e2b1 | 2012-07-19 00:32:01 | [diff] [blame] | 47 | JNIEnv* env = AttachCurrentThread(); |
[email protected] | 48224a7 | 2012-11-10 03:49:11 | [diff] [blame] | 48 | ScopedJavaLocalRef<jstring> j_url = ConvertUTF8ToJavaString(env, url.spec()); |
[email protected] | 82e9e2b1 | 2012-07-19 00:32:01 | [diff] [blame] | 49 | Java_Shell_onUpdateUrl(env, java_object_.obj(), j_url.obj()); |
[email protected] | a08029b4 | 2012-04-25 03:18:46 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | void Shell::PlatformSetIsLoading(bool loading) { |
[email protected] | 6a5fcf6f | 2012-09-29 14:18:40 | [diff] [blame] | 53 | JNIEnv* env = AttachCurrentThread(); |
| 54 | Java_Shell_setIsLoading(env, java_object_.obj(), loading); |
[email protected] | a08029b4 | 2012-04-25 03:18:46 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | void Shell::PlatformCreateWindow(int width, int height) { |
torne | b105fe3 | 2015-08-27 16:57:44 | [diff] [blame] | 58 | java_object_.Reset(CreateShellView(this)); |
[email protected] | a08029b4 | 2012-04-25 03:18:46 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | void Shell::PlatformSetContents() { |
[email protected] | 82e9e2b1 | 2012-07-19 00:32:01 | [diff] [blame] | 62 | JNIEnv* env = AttachCurrentThread(); |
| 63 | Java_Shell_initFromNativeTabContents( |
dtrainor | 25ee0c3f | 2015-01-27 20:15:53 | [diff] [blame] | 64 | env, java_object_.obj(), web_contents()->GetJavaWebContents().obj()); |
[email protected] | a08029b4 | 2012-04-25 03:18:46 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | void Shell::PlatformResizeSubViews() { |
| 68 | // Not needed; subviews are bound. |
| 69 | } |
| 70 | |
[email protected] | fcf75d4 | 2013-12-03 20:11:26 | [diff] [blame] | 71 | void Shell::PlatformSetTitle(const base::string16& title) { |
xhwang | 68722de | 2014-10-02 01:15:07 | [diff] [blame] | 72 | NOTIMPLEMENTED() << ": " << title; |
[email protected] | aecc085b | 2012-06-01 18:15:53 | [diff] [blame] | 73 | } |
| 74 | |
[email protected] | dbe9e95 | 2012-09-11 00:59:29 | [diff] [blame] | 75 | void Shell::LoadProgressChanged(WebContents* source, double progress) { |
[email protected] | 82e9e2b1 | 2012-07-19 00:32:01 | [diff] [blame] | 76 | JNIEnv* env = AttachCurrentThread(); |
| 77 | Java_Shell_onLoadProgressChanged(env, java_object_.obj(), progress); |
| 78 | } |
| 79 | |
[email protected] | 99c014c | 2012-11-27 12:03:42 | [diff] [blame] | 80 | void Shell::PlatformToggleFullscreenModeForTab(WebContents* web_contents, |
| 81 | bool enter_fullscreen) { |
[email protected] | dc9b4550 | 2012-11-22 07:44:17 | [diff] [blame] | 82 | JNIEnv* env = AttachCurrentThread(); |
| 83 | Java_Shell_toggleFullscreenModeForTab( |
| 84 | env, java_object_.obj(), enter_fullscreen); |
| 85 | } |
| 86 | |
[email protected] | 99c014c | 2012-11-27 12:03:42 | [diff] [blame] | 87 | bool Shell::PlatformIsFullscreenForTabOrPending( |
| 88 | const WebContents* web_contents) const { |
[email protected] | dc9b4550 | 2012-11-22 07:44:17 | [diff] [blame] | 89 | JNIEnv* env = AttachCurrentThread(); |
| 90 | return Java_Shell_isFullscreenForTabOrPending(env, java_object_.obj()); |
| 91 | } |
| 92 | |
[email protected] | a08029b4 | 2012-04-25 03:18:46 | [diff] [blame] | 93 | void Shell::Close() { |
[email protected] | fee3a78 | 2014-01-25 07:58:33 | [diff] [blame] | 94 | RemoveShellView(java_object_.obj()); |
[email protected] | 91c6e31 | 2013-05-29 12:41:52 | [diff] [blame] | 95 | delete this; |
[email protected] | a08029b4 | 2012-04-25 03:18:46 | [diff] [blame] | 96 | } |
| 97 | |
[email protected] | 82e9e2b1 | 2012-07-19 00:32:01 | [diff] [blame] | 98 | // static |
| 99 | bool Shell::Register(JNIEnv* env) { |
| 100 | return RegisterNativesImpl(env); |
| 101 | } |
| 102 | |
[email protected] | fee3a78 | 2014-01-25 07:58:33 | [diff] [blame] | 103 | // static |
torne | 89cc5d9 | 2015-09-04 11:16:35 | [diff] [blame] | 104 | void CloseShell(JNIEnv* env, |
| 105 | const JavaParamRef<jclass>& clazz, |
| 106 | jlong shellPtr) { |
[email protected] | fee3a78 | 2014-01-25 07:58:33 | [diff] [blame] | 107 | Shell* shell = reinterpret_cast<Shell*>(shellPtr); |
| 108 | shell->Close(); |
| 109 | } |
| 110 | |
[email protected] | a08029b4 | 2012-04-25 03:18:46 | [diff] [blame] | 111 | } // namespace content |