Bug 880121 - Add support for Browser (Chrome) application interfaces to GeckoView r=blassey

This commit is contained in:
Mark Finkle 2013-11-06 17:58:29 -05:00
Родитель 8f0f084fed
Коммит f8ec0ce9ab
3 изменённых файлов: 51 добавлений и 9 удалений

Просмотреть файл

@ -38,6 +38,8 @@ public class GeckoView extends LayerView
private static final String LOGTAG = "GeckoView";
private ChromeDelegate mChromeDelegate;
public GeckoView(Context context, AttributeSet attrs) {
super(context, attrs);
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.GeckoView);
@ -158,6 +160,11 @@ public class GeckoView extends LayerView
*/
public void handleMessage(String event, JSONObject message) {
if (event.equals("Gecko:Ready")) {
handleReady();
}
}
private void handleReady() {
GeckoThread.setLaunchState(GeckoThread.LaunchState.GeckoRunning);
Tab selectedTab = Tabs.getInstance().getSelectedTab();
if (selectedTab != null)
@ -167,9 +174,21 @@ public class GeckoView extends LayerView
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Viewport:Flush", null));
show();
requestRender();
if (mChromeDelegate != null) {
mChromeDelegate.onReady(this);
}
}
/**
* Set the chrome callback handler.
* This will replace the current handler.
* @param chrome An implementation of GeckoViewChrome.
*/
public void setChromeDelegate(ChromeDelegate chrome) {
mChromeDelegate = chrome;
}
public static void setGeckoInterface(final BaseGeckoInterface geckoInterface) {
GeckoAppShell.setGeckoInterface(geckoInterface);
}
@ -283,4 +302,12 @@ public class GeckoView extends LayerView
}
}
}
public interface ChromeDelegate {
/**
* Tell the host application that Gecko is ready to handle requests.
* @param view The GeckoView that initiated the callback.
*/
public void onReady(GeckoView view);
}
}

Просмотреть файл

@ -0,0 +1,14 @@
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.gecko;
public class GeckoViewChrome implements GeckoView.ChromeDelegate {
/**
* Tell the host application that Gecko is ready to handle requests.
* @param view The GeckoView that initiated the callback.
*/
public void onReady(GeckoView view) {}
}

Просмотреть файл

@ -148,6 +148,7 @@ gbjar.sources += [
'GeckoJavaSampler.java',
'GlobalHistory.java',
'GeckoView.java',
'GeckoViewChrome.java',
'health/BrowserHealthRecorder.java',
'health/BrowserHealthReporter.java',
'InputMethods.java',