$ sceDelegateProvider资源网址白名单无效

时间:2017-07-26 12:34:50

标签: javascript angularjs iframe

https://jsfiddle.net/BRNTZN/05c1agtb/18/

HTML:

public class MainActivity extends AppCompatActivity {

private BluetoothAdapter mBluetoothAdapter;
private BluetoothDevice mDevice;
private ConnectThread mConnectThread;
private String MAC = "30:14:10:17:06:93";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    TextView supportsBTorNot = (TextView) findViewById(R.id.supportsBTorNot);
    TextView listPairedDevices = (TextView) findViewById(R.id.listPairedDevices);

    mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

    if (mBluetoothAdapter == null) {
        supportsBTorNot.setText("The device does not support bluetooth.");
    }
    else{
        if (!mBluetoothAdapter.isEnabled()) {
            Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
            startActivityForResult(enableBtIntent, 1);
        }
        else{
            supportsBTorNot.setText("The device supports bluetooth.");
        }
    }

    Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices();
    listPairedDevices.setText(pairedDevices.toString());
    if (pairedDevices.size() > 0) {
        for (BluetoothDevice device : pairedDevices) {
            if(device.getAddress().equals(MAC)) {
                mDevice = device;
                break;
            }
        }
    }
    if (mDevice == null) {
        //Device is not paired yet
        //Need to initiate a connection request
    }

    mConnectThread = new ConnectThread(mDevice);
    mConnectThread.start();
}


private class ConnectThread extends Thread {

    private final BluetoothSocket mmSocket;
    private ConnectedThread mConnectedThread;
    private final UUID MY_UUID = UUID.fromString("00001101-0000-1000-8000-00805f9b34fb");

    TextView socketConnected = (TextView) findViewById(R.id.socketConnected);

    public ConnectThread(BluetoothDevice device) {
        BluetoothSocket tmp = null;
        try {
            tmp = device.createRfcommSocketToServiceRecord(MY_UUID);
        } catch (IOException e) { }
        mmSocket = tmp;
    }

    public void run() {
        mBluetoothAdapter.cancelDiscovery();
        try {
            mmSocket.connect();
        } catch (IOException connectException) {
            try {
                mmSocket.close();
            } catch (IOException closeException) { }
            return;
        }
        if (mmSocket.isConnected()) {
            socketConnected.setText("The socket is established successfully.");
        }
        else {
            socketConnected.setText("The socket could not be stablished.");
        }

        mConnectedThread = new ConnectedThread(mmSocket);
        mConnectedThread.start();
    }
}

JS:

<html>
<head>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js"></script>
    <script src="myapp.js"></script>
</head>
<body ng-app="myapp">
    <div ng-controller="mainctrl">
      {{query}}
      <iframe ng-src="https://www.google.be/search?q={{query}}"></iframe>
    </div>
</body>
</html>

当在小提琴之外做以上操作时,我在控制台中得到以下js错误:

var app = angular.module('myapp', []);

app.config(function($sceDelegateProvider) {
  $sceDelegateProvider.resourceUrlWhitelist([
    'self',
    'https://www.google.be/**'
  ]);
});

app.controller('mainctrl', function MainController($scope) {
  $scope.query = "javascript";
});

链接导致以下说明:

Error: [$interpolate:noconcat] http://errors.angularjs.org/1.5.6/$interpolate/noconcat?p0=https%3A%2F%2Fwww.google.be%2Fsearch%3Fq%3D%7B%7Bquery%7D%7D
    at angular.js:38
    at Function.Ka.throwNoconcat (angular.js:11887)
    at k (angular.js:12193)
    at ha (angular.js:9606)
    at $b (angular.js:8553)
    at s (angular.js:8378)
    at s (angular.js:8394)
    at s (angular.js:8394)
    at aa (angular.js:8281)
    at angular.js:1782

这很奇怪,因为我是白名单&#34; https://www.google.be/ **&#34;正如我的小提琴所证明的那样。

为什么白名单没有任何影响?

1 个答案:

答案 0 :(得分:0)

我认为ng-src不适用于$ sce。在小提琴中将ng-src更改为ng-bind-html。

  <iframe ng-bind-html="https://www.google.be/search?q={{query}}"></iframe>

https://jsfiddle.net/05c1agtb/19/