UNPKG

2.77 kBPlain TextView Raw
1/*
2 *
3 * Copyright 2013 Canonical Ltd.
4 *
5 * Licensed to the Apache Software Foundation (ASF) under one
6 * or more contributor license agreements. See the NOTICE file
7 * distributed with this work for additional information
8 * regarding copyright ownership. The ASF licenses this file
9 * to you under the Apache License, Version 2.0 (the
10 * "License"); you may not use this file except in compliance
11 * with the License. You may obtain a copy of the License at
12 *
13 * http://www.apache.org/licenses/LICENSE-2.0
14 *
15 * Unless required by applicable law or agreed to in writing,
16 * software distributed under the License is distributed on an
17 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18 * KIND, either express or implied. See the License for the
19 * specific language governing permissions and limitations
20 * under the License.
21 *
22*/
23import QtQuick 2.0
24import Ubuntu.Components.Popups 0.1
25import Ubuntu.Components 0.1
26import com.canonical.Oxide 1.0
27
28Rectangle {
29 anchors.fill: parent
30 id: inappbrowser
31 property string url1
32 Rectangle {
33 border.color: "black"
34 width: parent.width
35 height: urlEntry.height
36 color: "gray"
37 TextInput {
38 id: urlEntry
39 width: parent.width - closeButton.width
40 text: url1
41 activeFocusOnPress: false
42 }
43 Image {
44 id: closeButton
45 width: height
46 x: parent.width - width
47 height: parent.height
48 source: "close.png"
49 MouseArea {
50 anchors.fill: parent
51 onClicked: {
52 root.exec("InAppBrowser", "close", [0, 0])
53 }
54 }
55 }
56 }
57
58 property string usContext: "oxide://main-world/2"
59
60 function executeJS(scId, code) {
61 var req = _view.rootFrame.sendMessage(usContext, "EXECUTE", {code: code});
62
63 req.onreply = function(response) {
64 var code = 'cordova.callback(' + scId + ', JSON.parse(\'' + JSON.stringify(response.result) + '\'))';
65 console.warn(code);
66 cordova.javaScriptExecNeeded(code);
67 console.warn("RESP:" + JSON.stringify(response));
68 };
69 }
70
71 WebView {
72 width: parent.width
73 y: urlEntry.height
74 height: parent.height - y
75 url: url1
76 id: _view
77 onLoadingStateChanged: {
78 root.exec("InAppBrowser", "loadFinished", [_view.loading])
79 }
80 context: WebContext {
81 id: webcontext
82
83 userScripts: [
84 UserScript {
85 context: usContext
86 emulateGreasemonkey: true
87 url: "InAppBrowser_escapeScript.js"
88 }
89 ]
90 }
91 }
92}