blob: 111aff15bf78013b515321ec85996ac0e97dc80a [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"
dtrainor25ee0c3f2015-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;
36 Java_Shell_onNativeDestroyed(env, java_object_.obj());
[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;
43 Java_Shell_enableUiControl(env, java_object_.obj(), 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());
[email protected]82e9e2b12012-07-19 00:32:0149 Java_Shell_onUpdateUrl(env, java_object_.obj(), j_url.obj());
[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();
54 Java_Shell_setIsLoading(env, java_object_.obj(), 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();
63 Java_Shell_initFromNativeTabContents(
dtrainor25ee0c3f2015-01-27 20:15:5364 env, java_object_.obj(), web_contents()->GetJavaWebContents().obj());
[email protected]a08029b42012-04-25 03:18:4665}
66
67void Shell::PlatformResizeSubViews() {
68 // Not needed; subviews are bound.
69}
70
[email protected]fcf75d42013-12-03 20:11:2671void Shell::PlatformSetTitle(const base::string16& title) {
xhwang68722de2014-10-02 01:15:0772 NOTIMPLEMENTED() << ": " << title;
[email protected]aecc085b2012-06-01 18:15:5373}
74
[email protected]dbe9e952012-09-11 00:59:2975void Shell::LoadProgressChanged(WebContents* source, double progress) {
[email protected]82e9e2b12012-07-19 00:32:0176 JNIEnv* env = AttachCurrentThread();
77 Java_Shell_onLoadProgressChanged(env, java_object_.obj(), progress);
78}
79
[email protected]99c014c2012-11-27 12:03:4280void Shell::PlatformToggleFullscreenModeForTab(WebContents* web_contents,
81 bool enter_fullscreen) {
[email protected]dc9b45502012-11-22 07:44:1782 JNIEnv* env = AttachCurrentThread();
83 Java_Shell_toggleFullscreenModeForTab(
84 env, java_object_.obj(), enter_fullscreen);
85}
86
[email protected]99c014c2012-11-27 12:03:4287bool Shell::PlatformIsFullscreenForTabOrPending(
88 const WebContents* web_contents) const {
[email protected]dc9b45502012-11-22 07:44:1789 JNIEnv* env = AttachCurrentThread();
90 return Java_Shell_isFullscreenForTabOrPending(env, java_object_.obj());
91}
92
[email protected]a08029b42012-04-25 03:18:4693void Shell::Close() {
[email protected]fee3a782014-01-25 07:58:3394 RemoveShellView(java_object_.obj());
[email protected]91c6e312013-05-29 12:41:5295 delete this;
[email protected]a08029b42012-04-25 03:18:4696}
97
[email protected]82e9e2b12012-07-19 00:32:0198// static
99bool Shell::Register(JNIEnv* env) {
100 return RegisterNativesImpl(env);
101}
102
[email protected]fee3a782014-01-25 07:58:33103// static
torne89cc5d92015-09-04 11:16:35104void CloseShell(JNIEnv* env,
105 const JavaParamRef<jclass>& clazz,
106 jlong shellPtr) {
[email protected]fee3a782014-01-25 07:58:33107 Shell* shell = reinterpret_cast<Shell*>(shellPtr);
108 shell->Close();
109}
110
[email protected]a08029b42012-04-25 03:18:46111} // namespace content