<commit_before>define(function (require, exports, module) {
    "use strict";

    //TODO: 限制只有背景页可以使用？
    var derive = require("base/derive");
    var assert = require("base/assert");
    var NativeObject = require("boost/nativeObject/NativeObject");

    var FRONTPAGE_ID = -2;
    /**
     * 供背景页用作与前景页通信的中介（向前景页发送消息，监听前景页发来的消息）
     */
    var FrontPageNativeObject = derive(NativeObject, function () {
        NativeObject.call(this, null, FRONTPAGE_ID);
    }, {
        __onEvent: function (type, event) {
            //console.info(type, event);
            // 从前台页面传来的消息与页面刷新事件，抛出事件供背景页监听
            if (type === "message") {
                this.dispatchEvent({
                    type: "message",
                    data: event.data
                });
            } else if (type === "pagestarted") {
                this.dispatchEvent({
                    type: "pagestarted"
                });
            }
        },
        reload: function () {
            this.__callNative("reload", []);
        },
        loadUrl: function (url) {
            this.__callNative("loadUrl", [url]);
        },
        dispatchDocumentEvent: function (type, data) {
            var javascriptUrl = [
                "javascript:  (function(){",
                "   var data = " + JSON.stringify(data) + ";",
                "   var event = document.createEvent('Event');",
                "   event.initEvent(\"" + type + "\" , false, false);",
                "   event.data = data;",
                "   document.dispatchEvent(event);" +
                "})();"
            ].join('');
            this.loadUrl(javascriptUrl);
        }
    });

    module.exports = new FrontPageNativeObject();
});<commit_msg>改事件到window上去发<commit_after>define(function (require, exports, module) {
    "use strict";

    //TODO: 限制只有背景页可以使用？
    var derive = require("base/derive");
    var assert = require("base/assert");
    var NativeObject = require("boost/nativeObject/NativeObject");

    var FRONTPAGE_ID = -2;
    /**
     * 供背景页用作与前景页通信的中介（向前景页发送消息，监听前景页发来的消息）
     */
    var FrontPageNativeObject = derive(NativeObject, function () {
        NativeObject.call(this, null, FRONTPAGE_ID);
    }, {
        __onEvent: function (type, event) {
            //console.info(type, event);
            // 从前台页面传来的消息与页面刷新事件，抛出事件供背景页监听
            if (type === "message") {
                this.dispatchEvent({
                    type: "message",
                    data: event.data
                });
            } else if (type === "pagestarted") {
                this.dispatchEvent({
                    type: "pagestarted"
                });
            }
        },
        reload: function () {
            this.__callNative("reload", []);
        },
        loadUrl: function (url) {
            this.__callNative("loadUrl", [url]);
        },
        dispatchWindowEvent: function (type, data) {
            var javascriptUrl = [
                "javascript:  (function(){",
                "   var data = " + JSON.stringify(data) + ";",
                "   var event = document.createEvent('Event');",
                "   event.initEvent(\"" + type + "\" , false, false);",
                "   event.data = data;",
                "   window.dispatchEvent(event);" +
                "})();"
            ].join('');
            //console.info(javascriptUrl);
            this.loadUrl(javascriptUrl);
        }
    });

    module.exports = new FrontPageNativeObject();
});
{'fraction_non_alphanumeric': 0.1442114334961218, 'fraction_numerical': 0.0005745475438092502, 'mean_word_length': 1.5888475836431226, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7296519', 'n_tokens_mistral': 1072, 'n_tokens_neox': 1089, 'n_words': 169}