(function(define, require, requireNative, requireAsync, exports, conso การแปล - (function(define, require, requireNative, requireAsync, exports, conso ไทย วิธีการพูด

(function(define, require, requireN

(function(define, require, requireNative, requireAsync, exports, console, privates,$Array, $Function, $JSON, $Object, $RegExp, $String, $Error) {'use strict';// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// chrome.runtime.messaging API implementation.

// TODO(kalman): factor requiring chrome out of here.
var chrome = requireNative('chrome').GetChrome();
var Event = require('event_bindings').Event;
var lastError = require('lastError');
var logActivity = requireNative('activityLogger');
var logging = requireNative('logging');
var messagingNatives = requireNative('messaging_natives');
var processNatives = requireNative('process');
var utils = require('utils');
var messagingUtils = require('messaging_utils');

// The reserved channel name for the sendRequest/send(Native)Message APIs.
// Note: sendRequest is deprecated.
var kRequestChannel = "chrome.extension.sendRequest";
var kMessageChannel = "chrome.runtime.sendMessage";
var kNativeMessageChannel = "chrome.runtime.sendNativeMessage";

// Map of port IDs to port object.
var ports = {};

// Change even to odd and vice versa, to get the other side of a given
// channel.
function getOppositePortId(portId) { return portId ^ 1; }

// Port object. Represents a connection to another script context through
// which messages can be passed.
function PortImpl(portId, opt_name) {
this.portId_ = portId;
this.name = opt_name;

var portSchema = {name: 'port', $ref: 'runtime.Port'};
var options = {unmanaged: true};
this.onDisconnect = new Event(null, [portSchema], options);
this.onMessage = new Event(
null,
[{name: 'message', type: 'any', optional: true}, portSchema],
options);
this.onDestroy_ = null;
}

// Sends a message asynchronously to the context on the other end of this
// port.
PortImpl.prototype.postMessage = function(msg) {
// JSON.stringify doesn't support a root object which is undefined.
if (msg === undefined)
msg = null;
msg = $JSON.stringify(msg);
if (msg === undefined) {
// JSON.stringify can fail with unserializable objects. Log an error and
// drop the message.
//
// TODO(kalman/mpcomplete): it would be better to do the same validation
// here that we do for runtime.sendMessage (and variants), i.e. throw an
// schema validation Error, but just maintain the old behaviour until
// there's a good reason not to (http://crbug.com/263077).
console.error('Illegal argument to Port.postMessage');
return;
}
messagingNatives.PostMessage(this.portId_, msg);
};

// Disconnects the port from the other end.
PortImpl.prototype.disconnect = function() {
messagingNatives.CloseChannel(this.portId_, true);
this.destroy_();
};

PortImpl.prototype.destroy_ = function() {
if (this.onDestroy_)
this.onDestroy_();
privates(this.onDisconnect).impl.destroy_();
privates(this.onMessage).impl.destroy_();
messagingNatives.PortRelease(this.portId_);
delete ports[this.portId_];
};

// Returns true if the specified port id is in this context. This is used by
// the C++ to avoid creating the javascript message for all the contexts that
// don't care about a particular message.
function hasPort(portId) {
return portId in ports;
};

// Hidden port creation function. We don't want to expose an API that lets
// people add arbitrary port IDs to the port list.
function createPort(portId, opt_name) {
if (ports[portId])
throw new Error("Port '" + portId + "' already exists.");
var port = new Port(portId, opt_name);
ports[portId] = port;
messagingNatives.PortAddRef(portId);
return port;
};

// Helper function for dispatchOnRequest.
function handleSendRequestError(isSendMessage,
responseCallbackPreserved,
sourceExtensionId,
targetExtensionId,
sourceUrl) {
var errorMsg = [];
var eventName = isSendMessage ? "runtime.onMessage" : "extension.onRequest";
if (isSendMessage && !responseCallbackPreserved) {
$Array.push(errorMsg,
"The chrome." + eventName + " listener must return true if you " +
"want to send a response after the listener returns");
} else {
$Array.push(errorMsg,
"Cannot send a response more than once per chrome." + eventName +
" listener per document");
}
$Array.push(errorMsg, "(message was sent by extension" + sourceExtensionId);
if (sourceExtensionId != "" && sourceExtensionId != targetExtensionId)
$Array.push(errorMsg, "for extension " + targetExtensionId);
if (sourceUrl != "")
$Array.push(errorMsg, "for URL " + sourceUrl);
lastError.set(eventName, errorMsg.join(" ") + ").", null, chrome);
}

// Helper function for dispatchOnConnect
function dispatchOnRequest(portId, channelName, sender,
sourceExtensionId, targetExtensionId, sourceUrl,
isExternal) {
var isSendMessage = channelName == kMessageChannel;
var requestEvent = null;
if (isSendMessage) {
if (chrome.runtime) {
requestEvent = isExternal ? chrome.runtime.onMessageExternal
: chrome.runtime.onMessage;
}
} else {
if (chrome.extension) {
requestEvent = isExternal ? chrome.extension.onRequestExternal
: chrome.extension.onRequest;
}
}
if (!requestEvent)
return false;
if (!requestEvent.hasListeners())
return false;
var port = createPort(portId, channelName);

function messageListener(request) {
var responseCallbackPreserved = false;
var responseCallback = function(response) {
if (port) {
port.postMessage(response);
privates(port).impl.destroy_();
port = null;
} else {
// We nulled out port when sending the response, and now the page
// is trying to send another response for the same request.
handleSendRequestError(isSendMessage, responseCallbackPreserved,
sourceExtensionId, targetExtensionId);
}
};
// In case the extension never invokes the responseCallback, and also
// doesn't keep a reference to it, we need to clean up the port. Do
// so by attaching to the garbage collection of the responseCallback
// using some native hackery.
//
// If the context is destroyed before this has a chance to execute,
// BindToGC knows to release |portId| (important for updating C++ state
// both in this renderer and on the other end). We don't need to clear
// any JavaScript state, as calling destroy_() would usually do - but
// the context has been destroyed, so there isn't any JS state to clear.
messagingNatives.BindToGC(responseCallback, function() {
if (port) {
privates(port).impl.destroy_();
port = null;
}
}, portId);
var rv = requestEvent.dispatch(request, sender, responseCallback);
if (isSendMessage) {
responseCallbackPreserved =
rv && rv.results && $Array.indexOf(rv.results, true) > -1;
if (!responseCallbackPreserved && port) {
// If they didn't access the response callback, they're not
// going to send a response, so clean up the port immediately.
privates(port).impl.destroy_();
port = null;
}
}
}

privates(port).impl.onDestroy_ = function() {
port.onMessage.removeListener(messageListener);
};
port.onMessage.addListener(messageListener);

var eventName = isSendMessage ? "runtime.onMessage" : "extension.onRequest";
if (isExternal)
eventName += "External";
logActivity.LogEvent(targetExtensionId,
eventName,
[sourceExtensionId, sourceUrl]);
return true;
}

// Called by native code when a channel has been opened to this context.
function dispatchOnConnect(portId,
channelName,
sourceTab,
sourceFrameId,
guestProcessId,
guestRenderFrameRoutingId,
sourceExtensionId,
targetExtensionId,
sourceUrl,
tlsChannelId) {
// Only create a new Port if someone is actually listening for a connection.
// In addition to being an optimization, this also fixes a bug where if 2
// channels were opened to and from the same process, closing one would
// close both.
var extensionId = processNatives.GetExtensionId();

// messaging_bindings.cc should ensure that this method only gets called for
// the right extension.
logging.CHECK(targetExtensionId == extensionId);

if (ports[getOppositePortId(portId)])
return false; // this channel was opened by us, so ignore it

// Determine whether this is coming from another extension, so we can use
// the right event.
var isExternal = sourceExtensionId != extensionId;

var sender = {};
if (sourceExtensionId != '')
sender.id = sourceExtensionId;
if (sourceUrl)
sender.url = sourceUrl;
if (sourceTab)
sender.tab = sourceTab;
if (sourceFrameId >= 0)
sender.frameId = sourceFrameId;
if (typeof guestProcessId !== 'undefined' &&
typeof guestRenderFrameRoutingId !== 'undefined') {
// Note that |guestProcessId| and |guestRenderFrameRoutingId| are not
// standard fields on MessageSender and should not
0/5000
จาก: -
เป็น: -
ผลลัพธ์ (ไทย) 1: [สำเนา]
คัดลอก!
(ฟังก์ชัน (กำหนด ต้อง requireNative, requireAsync ส่งออก คอนโซล โจร $Array, $Function, $JSON, $Object, $RegExp, $String, $Error) { 'ใช้เข้มงวด'; / / โครเมียมลิขสิทธิ์ 2014 ผู้เขียน สงวนลิขสิทธิ์ทั้งหมดใช้โค้ดนี้อยู่ภายใต้ใบอนุญาตแบบ BSD ที่สามารถพบในแฟ้มลิขสิทธิ์ใช้ chrome.runtime.messaging API TODO(kalman): ปัจจัยที่ต้องใช้โครเมี่ยมออกจากที่นี่ โครเมี่ยม var = requireNative('chrome') GetChrome() เหตุการณ์ var = require('event_bindings') เหตุการณ์ var lastError = require('lastError') var logActivity = requireNative('activityLogger') เข้าสู่ระบบ var = requireNative('logging') var messagingNatives = requireNative('messaging_natives') var processNatives = requireNative('process') var utils = require('utils') var messagingUtils = require('messaging_utils') ชื่อช่องจอง sendRequest/ส่ง APIs ข้อ (พื้นเมือง) หมายเหตุ: sendRequest จะถูกตัดออก var kRequestChannel = "chrome.extension.sendRequest" var kMessageChannel = "chrome.runtime.sendMessage" var kNativeMessageChannel = "chrome.runtime.sendNativeMessage" แผนที่ท่ารหัสวัตถุพอร์ต พอร์ตของ var ={}; เปลี่ยนแปลงแม้ จะแปลก ๆ และในทางกลับ กัน ไปด้านอื่น ๆ ของการกำหนด ช่องทางการ ฟังก์ชัน getOppositePortId(portId) {กลับ portId ^ 1; } ออปเจ็กต์พอร์ต แสดงถึงการเชื่อมต่อกับบริบทสคริปต์อื่นผ่าน ข้อความที่สามารถถูกส่งผ่าน ฟังก์ชัน{PortImpl (portId, opt_name) this.portId_ = portId this.name = opt_name var portSchema = {ชื่อ: 'ท่าเรือ' $ref: "รันไทม์ ท่า ' }; ตัวเลือก var = {จัดการ: จริง}; this.onDisconnect =เหตุการณ์ใหม่ (null, [portSchema], ตัว); this.onMessage =(เหตุการณ์ใหม่ null [{ชื่อ: 'ข้อความ' พิมพ์: 'ใดๆ' ไม่จำเป็น: ความจริง}, portSchema], ตัว); this.onDestroy_ =เป็น null } ส่งข้อความแบบอะซิงโครนัสกับบริบทในส่วนอื่น ๆ ของ พอร์ต PortImpl.prototype.postMessage = function(msg) { JSON.stringify ไม่สนับสนุนวัตถุรากที่ไม่ได้กำหนด ถ้า (ผงชูรส === ไม่ได้กำหนด) ผงชูรส = null ผงชูรส = $JSON.stringify(msg) ถ้า (ผงชูรส === ไม่) { JSON.stringify กับ unserializable วัตถุไม่สามารถ ล็อกข้อผิดพลาด และ ฝากข้อความ // TODO(kalman/mpcomplete): มันจะดีกว่าที่จะทำการตรวจสอบเดียวกัน ที่นี่ที่เรา runtime.sendMessage (และตัวแปร), เช่นโยน ผิด แผนตรวจสอบข้อผิดพลาด แต่เพียงรักษาพฤติกรรมเก่าจน มีเหตุผลที่ดีไม่ให้ (ส่วน http://crbug.com/263077) console.error ('ไม่ถูกต้องอาร์กิวเมนต์ Port.postMessage'); กลับ } messagingNatives.PostMessage (this.portId_ ผงชูรส); }; ยกเลิกติดต่อพอร์ตจากอีกฝ่าย PortImpl.prototype.disconnect = function() { messagingNatives.CloseChannel (this.portId_ จริง); this.destroy_() }; PortImpl.prototype.destroy_ = function() { ถ้า (this.onDestroy_) this.onDestroy_() privates(this.onDisconnect).impl.destroy_() privates(this.onMessage).impl.destroy_() messagingNatives.PortRelease(this.portId_) ลบ ports[this.portId_]; }; ส่งกลับ true ถ้าหมายเลขพอร์ตที่ระบุในบริบทนี้ ใช้โดย c ++เพื่อหลีกเลี่ยงการสร้างข้อความ javascript ในบริบททั้งหมดที่ ไม่ดูแลเกี่ยวกับข้อ {hasPort(portId) ฟังก์ชัน คืน portId พอร์ต }; ซ่อนฟังก์ชันการสร้างท่าเรือ เราไม่ต้องการเปิดเผยเป็น API ที่ช่วยให้ คนเพิ่มพอร์ตกำหนดรหัสรายการพอร์ต ฟังก์ชัน createPort (portId, opt_name) { ถ้า (ports[portId]) ข้อผิดพลาดใหม่โยน ("พอร์ต ' " + portId + "' แล้ว"); ท่า var =ท่าใหม่ (portId, opt_name); พอร์ต [portId] =ท่า messagingNatives.PortAddRef(portId) กลับท่าเรือ }; ฟังก์ชันผู้ช่วยเหลือสำหรับ dispatchOnRequest ฟังก์ชัน handleSendRequestError(isSendMessage, responseCallbackPreserved sourceExtensionId targetExtensionId {sourceUrl) var errorMsg =[]; var eventName = isSendMessage "runtime.onMessage": "extension.onRequest" ถ้า (isSendMessage & & ! responseCallbackPreserved) { $Array.push (errorMsg "แบบโครเมี่ยม" + eventName + "ฟังต้องส่งกลับ true ถ้าคุณ" + "ต้องการส่งการตอบสนองหลังจากที่ฟังกลับ"); } {อื่น $Array.push (errorMsg "ไม่สามารถส่งการตอบสนองมากกว่าหนึ่งครั้งต่อโครเมี่ยม" + eventName + "ฟังต่อเอกสาร"); } $Array.push (errorMsg, "(ข้อความถูกส่ง โดยนามสกุล" + sourceExtensionId); ถ้า (sourceExtensionId ! = "" & & sourceExtensionId ! = targetExtensionId) $Array.push (errorMsg "สำหรับนามสกุล" + targetExtensionId); ถ้า (sourceUrl ! = "") $Array.push (errorMsg "สำหรับ URL" + sourceUrl); lastError.set (eventName, errorMsg.join("") + ") null โครเมี่ยม); } ฟังก์ชันผู้ช่วยเหลือ dispatchOnConnect ฟังก์ชัน dispatchOnRequest (portId, channelName ผู้ ส่ง sourceExtensionId, targetExtensionId, sourceUrl {isExternal) var isSendMessage = channelName == kMessageChannel var requestEvent = null ถ้า{(isSendMessage) ถ้า{(chrome.runtime) requestEvent = isExternal chrome.runtime.onMessageExternal : chrome.runtime.onMessage } } {อื่น ถ้า{(chrome.extension) requestEvent = isExternal chrome.extension.onRequestExternal : chrome.extension.onRequest } } ถ้า (! requestEvent) ส่งคืนเท็จ ถ้า (! requestEvent.hasListeners()) ส่งคืนเท็จ ท่า var = createPort (portId, channelName); {messageListener(request) ฟังก์ชัน var responseCallbackPreserved = false var responseCallback = function(response) { ถ้า{(พอร์ต) port.postMessage(response) privates(port).impl.destroy_() ท่าเรือ = null } {อื่น เรา nulled ออกพอร์ตเมื่อส่งการตอบสนอง และตอนนี้หน้า กำลังส่งการตอบสนองคำขอเดียวกันอีก handleSendRequestError (isSendMessage, responseCallbackPreserved sourceExtensionId, targetExtensionId); } }; ในกรณีที่ส่วนขยายจะไม่ responseCallback และ ไม่ให้อ้างอิงไป เราจำเป็นต้องล้างพอร์ต ทำ โดยเก็บรวบรวมขยะของ responseCallback แนบดังกล่าว ใช้ hackery เป็นบาง // ถ้าบริบทถูกทำลายก่อนนี้มีโอกาสที่จะดำเนินการ BindToGC รู้ปล่อย |portId| (สำคัญสำหรับการปรับปรุงสถานะ c ++ ทั้งสองตัวนี้ และในส่วนอื่น ๆ) เราไม่จำเป็นต้องล้าง จาวาสคริปต์ใด ๆ รัฐ เป็นมักจะทำการเรียก destroy_() - แต่ บริบทเสียหาย จึงไม่มีรัฐใด JS ล้าง messagingNatives.BindToGC (responseCallback, function() { ถ้า{(พอร์ต) privates(port).impl.destroy_() ท่าเรือ = null } }, portId); var rv = requestEvent.dispatch (ขอ ผู้ส่ง responseCallback); ถ้า{(isSendMessage) responseCallbackPreserved = rv & & rv.results และ & $Array.indexOf (rv.results จริง) > -1 ถ้า (! responseCallbackPreserved & และพอร์ต) { ถ้าไม่เข้ากลับตอบรับ พวกเขาไม่ จะส่งการตอบสนอง ครับค่าพอร์ตทันที privates(port).impl.destroy_() ท่าเรือ = null } } } โจร (พอร์ต) .impl.onDestroy_ = function() { port.onMessage.removeListener(messageListener) }; port.onMessage.addListener(messageListener) var eventName = isSendMessage "runtime.onMessage": "extension.onRequest" ถ้า (isExternal) eventName += "ภายนอก" logActivity.LogEvent (targetExtensionId eventName [sourceExtensionId, sourceUrl]); กลับเป็นจริง } เรียกตามพื้นเมืองรหัสเมื่อเปิดสถานีกับบริบทนี้ ฟังก์ชัน dispatchOnConnect(portId, channelName sourceTab sourceFrameId guestProcessId guestRenderFrameRoutingId sourceExtensionId targetExtensionId sourceUrl {tlsChannelId) สร้างพอร์ตใหม่เท่านั้น ถ้าคนจะฟังสำหรับการเชื่อมต่อ นอกจากจะมีประสิทธิภาพสูงสุด นี้ยังแก้ไขบกพร่องซึ่งถ้า 2 เปิดช่องทางเข้า และออก จาก กระบวนการเดียวกัน ปิดหนึ่งจะ ปิดทั้งสอง var extensionId = processNatives.GetExtensionId() messaging_bindings.cc ควรให้แน่ใจว่า วิธีนี้เท่านั้นจะเรียก ส่วนขยายที่เหมาะสม เข้าสู่ระบบ CHECK(targetExtensionId == extensionId) ถ้า (ports[getOppositePortId(portId)]) ส่งคืนเท็จ เปิดช่องนี้เรา ดังนั้นให้ ละเว้น กำหนดว่า นี้มาจากนามสกุลอื่น เพื่อให้เราสามารถใช้ เหตุการณ์เหมาะสม var isExternal = sourceExtensionId ! = extensionId ผู้ส่ง var ={}; ถ้า (sourceExtensionId ! = '') sender.id = sourceExtensionId ถ้า (sourceUrl) sender.url = sourceUrl ถ้า (sourceTab) sender.tab = sourceTab ถ้า (sourceFrameId > = 0) sender.frameId = sourceFrameId ถ้า (typeof guestProcessId ! == 'ยังไม่ได้กำหนด' & & typeof guestRenderFrameRoutingId ! == 'ยังไม่ได้กำหนด') { หมายเหตุที่ |guestProcessId| และ |guestRenderFrameRoutingId| ไม่ เขตข้อมูลใน MessageSender และไม่ควร
การแปล กรุณารอสักครู่..
ผลลัพธ์ (ไทย) 2:[สำเนา]
คัดลอก!
(ฟังก์ชั่น (กำหนดต้องการ requireNative, requireAsync ส่งออกคอนโซลเอกชน, อาร์เรย์ $, ฟังก์ชั่น $, $ JSON, $ วัตถุ RegExp $, $ สตริงข้อผิดพลาด $) {'ใช้อย่างเข้มงวด'; // ลิขสิทธิ์ 2014 โครเมียม . ผู้เขียนสงวนลิขสิทธิ์.
// การใช้รหัสต้นฉบับนี้อยู่ภายใต้ใบอนุญาต BSD สไตล์ที่สามารถ
// พบในแฟ้มใบอนุญาต. // chrome.runtime.messaging การดำเนินงาน API. // สิ่งที่ต้องทำ (คาลมาน): ปัจจัย . ต้องมีโครเมี่ยมออกจากที่นี่var โครเมี่ยม = requireNative (โครเมี่ยม) GetChrome ();. var เหตุการณ์ = ต้อง (event_bindings) เหตุการณ์. var lastError = ต้อง (lastError '); var logActivity = requireNative (activityLogger' ); var เข้าสู่ระบบ = requireNative ('เข้าสู่ระบบ'); var messagingNatives = requireNative (messaging_natives '); var processNatives = requireNative (' กระบวนการ '); var utils = ต้อง (utils'); var messagingUtils = ต้อง (messaging_utils ' ); // ชื่อช่องสงวนไว้สำหรับ SendRequest / ส่ง (พื้นเมือง) APIs ข้อความ. //. หมายเหตุ: SendRequest จะเลิกvar kRequestChannel = "chrome.extension.sendRequest"; var kMessageChannel = "chrome.runtime.sendMessage"; var kNativeMessageChannel = "chrome.runtime.sendNativeMessage";. // แผนที่ของรหัสพอร์ตไปยังวัตถุพอร์ตvar พอร์ต = {}; // เปลี่ยนแม้กระทั่งในทางกลับกันแปลกและรองเพื่อให้ได้ด้านอื่น ๆ ของที่กำหนด. ช่อง // getOppositePortId ฟังก์ชั่น (portId) {กลับ portId ^ 1; } // วัตถุพอร์ต แสดงให้เห็นถึงการเชื่อมต่อกับบริบทสคริปต์อื่นผ่าน. // ข้อความที่สามารถส่งผ่านไปทำงานPortImpl (portId, opt_name) {this.portId_ = portId; this.name = opt_name; var portSchema = {ชื่อ: 'ท่าเรือ', $ Ref: ' runtime.Port '}; ตัวเลือก var = {ไม่มีการจัดการ: จริง}; this.onDisconnect = เหตุการณ์ใหม่ (โมฆะ [portSchema] ตัวเลือก); this.onMessage = เหตุการณ์ใหม่ (โมฆะ[{ชื่อ:' ข้อความ 'พิมพ์: 'ใด ๆ ' ตัวเลือก: จริง} portSchema] ตัวเลือก); this.onDestroy_ = null;} // ส่งข้อความถ่ายทอดสดกับบริบทในส่วนอื่น ๆ ของเรื่องนี้. พอร์ต // PortImpl.prototype.postMessage = function (ผงชูรส ) {// JSON.stringify ไม่สนับสนุนวัตถุรากซึ่งจะไม่ได้กำหนด. ถ้า (ผงชูรส === ไม่ได้กำหนด) ผงชูรส = null; ผงชูรส = $ JSON.stringify (ข); if (ผงชูรส === ไม่ได้กำหนด) {/ / JSON.stringify สามารถล้มเหลวกับวัตถุ unserializable เข้าสู่ระบบข้อผิดพลาดและ// วางข้อความ. // // สิ่งที่ต้องทำ (คาลมาน / mpcomplete): มันจะดีกว่าที่จะทำตรวจสอบเดียวกัน// นี่ที่เราทำเพื่อ runtime.sendMessage (และตัวแปร) คือโยน// การตรวจสอบข้อผิดพลาดคีมา แต่เพียงรักษาพฤติกรรมเก่าจน// มีเหตุผลที่ดีที่จะไม่ (http://crbug.com/263077). console.error ('อาร์กิวเมนต์ที่ผิดกฎหมายที่จะ Port.postMessage'); กลับมา;} messagingNatives PostMessage (this.portId_, ผงชูรส);}; // ยกเลิกการเชื่อมต่อพอร์ตจากส่วนอื่น ๆ . PortImpl.prototype.disconnect = function () {messagingNatives.CloseChannel (this.portId_ จริง); this.destroy_ ();}; PortImpl.prototype.destroy_ = function () {ถ้า พอร์ต [this.portId_];}; // ผลตอบแทนจริงถ้ารหัสพอร์ตที่ระบุอยู่ในบริบทนี้ นี้ถูกใช้โดย// c ++ ที่จะหลีกเลี่ยงการสร้างข้อความจาวาสคริปต์สำหรับบริบททั้งหมดที่. // ไม่สนใจเกี่ยวกับข้อความโดยเฉพาะอย่างยิ่งทำงานhasPort (portId) {กลับportId ในพอร์ต;}; // พอร์ตที่ซ่อนอยู่ฟังก์ชั่นการสร้าง เราไม่ต้องการที่จะเปิดเผย API ที่ช่วยให้// คนเพิ่มรหัสพอร์ตโดยพลการในรายการพอร์ต. ทำงาน createPort (portId, opt_name) {if (พอร์ต [portId]) โยนข้อผิดพลาดใหม่ ("พอร์ต" portId + + " 'อยู่แล้ว. "); พอร์ต var = พอร์ตใหม่ (portId, opt_name); พอร์ต [portId] = พอร์ตmessagingNatives.PortAddRef (portId); พอร์ตกลับ;}; // ฟังก์ชั่นสำหรับผู้ช่วย dispatchOnRequest. ฟังก์ชั่น {var errorMsg = []; var eventName = isSendMessage? "runtime.onMessage": "extension.onRequest"; if (isSendMessage && responseCallbackPreserved!) {$ Array.push (errorMsg, "โครเมี่ยม." eventName + + "ผู้ฟังจะต้องกลับจริงถ้าคุณ" + "ต้องการที่จะส่งการตอบสนอง หลังจากที่ผลตอบแทนที่ผู้ฟัง ");} else {$ Array.push (errorMsg," ไม่สามารถส่งการตอบสนองมากกว่าหนึ่งครั้งต่อโครเมี่ยม "+ + eventName." ฟังต่อเอกสาร ");} $ Array.push (errorMsg" (ข้อความ ถูกส่งโดยขยาย "+ sourceExtensionId); if (sourceExtensionId =" "&& sourceExtensionId = targetExtensionId)! $ Array.push (errorMsg" ขยาย "+ targetExtensionId); if! (sourceUrl =" ") $ Array.push ( errorMsg "สำหรับ URL" + sourceUrl); lastError.set (eventName, errorMsg.join ("") + ")" โมฆะ, โครเมี่ยม);.} // ฟังก์ชั่นสำหรับผู้ช่วย dispatchOnConnect dispatchOnRequest ฟังก์ชั่น (portId, channelName ผู้ส่ง, sourceExtensionId, targetExtensionId, sourceUrl, isExternal) {var isSendMessage = channelName == kMessageChannel; var requestEvent = null; if (isSendMessage) {if (chrome.runtime) {requestEvent = isExternal? chrome.runtime.onMessageExternal: chrome.runtime.onMessage;}} else {if (chrome.extension) {requestEvent = isExternal? chrome.extension.onRequestExternal: chrome.extension.onRequest;}} ถ้า (! requestEvent) กลับเท็จ; if (! requestEvent.hasListeners ()) กลับเท็จ; พอร์ต var = createPort (portId, channelName); messageListener ฟังก์ชั่น (ตามคำขอ) { var responseCallbackPreserved = false; var responseCallback = function (การตอบสนอง) {ถ้า(พอร์ต) {port.postMessage (การตอบสนอง); เอกชน (พอร์ต) .impl.destroy_ (); พอร์ต = null;} else {// เรา nulled ออกพอร์ตเมื่อ ส่งการตอบสนองและตอนนี้หน้า// พยายามที่จะส่งการตอบสนองสำหรับการร้องขอเดียวกันอีก. handleSendRequestError (isSendMessage, responseCallbackPreserved, sourceExtensionId, targetExtensionId);}}; // ในกรณีที่ขยายไม่เคยเรียก responseCallback และยัง// ไม่ให้การอ้างอิงถึงมันเราต้องทำความสะอาดพอร์ต ทำ// ได้โดยแนบกับการเก็บขยะของ responseCallback ที่// ใช้บาง hackery พื้นเมือง. // // ถ้าบริบทถูกทำลายก่อนหน้านี้มีโอกาสที่จะดำเนินการ, // BindToGC รู้ที่จะปล่อย | portId | (สำคัญสำหรับการปรับปรุงรัฐ C ++ // ทั้งใน renderer นี้และในส่วนอื่น ๆ ) เราไม่จำเป็นต้องล้าง// ใดรัฐ JavaScript, เป็นโทร destroy_ () มักจะไม่ - แต่// บริบทได้ถูกทำลายจึงมีไม่ใด ๆ ของรัฐเพื่อล้าง JS. messagingNatives.BindToGC (responseCallback ฟังก์ชั่น ( ) {ถ้า(พอร์ต) {เอกชน(พอร์ต) .impl.destroy_ (); พอร์ต = null;}} portId); RV var = requestEvent.dispatch (ขอผู้ส่ง responseCallback); if (isSendMessage) {responseCallbackPreserved = RV && && $ rv.results Array.indexOf (rv.results จริง)> -1; if (! responseCallbackPreserved && พอร์ต) {// ถ้าพวกเขาไม่ได้โทรกลับเข้าสู่การตอบสนองพวกเขาไม่ได้// จะไปส่ง การตอบสนองเพื่อให้ทำความสะอาดพอร์ตทันที. เอกชน (พอร์ต) .impl.destroy_ (); พอร์ต = null;}}} เอกชน (พอร์ต) .impl.onDestroy_ = ฟังก์ชั่น () {port.onMessage.removeListener (messageListener);} ; port.onMessage.addListener (messageListener); var eventName = isSendMessage? "runtime.onMessage": "extension.onRequest"; if (isExternal) eventName + = "ภายนอก"; logActivity.LogEvent (targetExtensionId, eventName, [sourceExtensionId, sourceUrl]); กลับจริง;} // เรียกได้ว่ารหัสพื้นเมืองเมื่อ ช่องทางที่ได้รับการเปิดให้บริบทนี้. ฟังก์ชั่น {// เพียงสร้างท่าเรือใหม่ถ้ามีใครฟังจริงสำหรับการเชื่อมต่อ. // นอกจากจะเพิ่มประสิทธิภาพนี้ยังแก้ไขข้อผิดพลาดที่ถ้า 2 ช่อง // เปิดไปและกลับจากกระบวนการเดียวกันปิดหนึ่งจะ/ . / ปิดทั้งvar extensionId = processNatives.GetExtensionId (); // messaging_bindings.cc ควรให้แน่ใจว่าวิธีการนี้เท่านั้นที่ได้รับการเรียกร้องให้มี// นามสกุลที่ถูกต้อง. logging.CHECK (targetExtensionId == extensionId); if (พอร์ต [getOppositePortId (portId )]) กลับเท็จ; // ช่องทางนี้ถูกเปิดออกโดยเราจึงไม่สนใจมัน// ตรวจสอบว่านี้จะมาจากการขยายอีกดังนั้นเราจึงสามารถใช้// เหตุการณ์ที่เหมาะสม. var isExternal = = sourceExtensionId extensionId; var ผู้ส่ง = {}; if (sourceExtensionId ! = '') sender.id = sourceExtensionId; if (sourceUrl) sender.url = sourceUrl; if (sourceTab) sender.tab = sourceTab; if (sourceFrameId> = 0) sender.frameId = sourceFrameId;! if (typeof guestProcessId = = 'ไม่ได้กำหนด' && typeof guestRenderFrameRoutingId == 'ไม่ได้กำหนด') {! // โปรดทราบว่า | guestProcessId | และ | guestRenderFrameRoutingId | ไม่ได้// สาขามาตรฐานใน MessageSender และไม่ควร


















































































































































































































































การแปล กรุณารอสักครู่..
ผลลัพธ์ (ไทย) 3:[สำเนา]
คัดลอก!
( -- ใช้ define , สั่งของ , requirenative , requireasync , exports , console กล่าวว่า , array , อง -- , อง json , อง object , อง regexp , อง string , องปิด ) { 'use strict ' ; / / copyright 2014 the chromium authors . สงวนลิขสิทธิ์ .
/ / ใช้โค้ดนี้ถูกควบคุมโดยใบอนุญาต BSD สไตล์ที่สามารถ
/ / ที่พบในแฟ้มใบอนุญาต .

/ / chrome.runtime.messaging API การ

/ / สิ่งที่ต้องทำ ( คาลมาน )ปัจจัยที่ใช้ Chrome ออกมา
var Chrome = requirenative ( 'chrome ' ) getchrome() ;
วาร์เหตุการณ์ = ต้อง ( 'event_bindings ' ) เหตุการณ์ ;
lasterror var = ต้อง ( 'lasterror ' ) ;
logactivity var = requirenative ( 'activitylogger ' ) ;
var เข้าสู่ระบบ = requirenative ( 'logging ' ) ;
messagingnatives วาร์ = requirenative ( 'messaging_natives ' ) ;
processnatives var = requirenative ( 'process
' ) ;var utils = สั่งของ ( 'utils ' ) ;
var messagingutils = สั่งของ ( 'messaging_utils ' ) ; เก็บกวาดเก็บกวาด / / the reserved channel name for the sendrequest / send ( native ) ของ apis . note
/ / : sendrequest is deprecated .
var krequestchannel = " ดีนิ . รถมอเตอร์ไซค์ใน sendrequest " ;
var kmessagechannel = " โครเมี่ยม ทำงาน . sendmessage " ;
knativemessagechannel var = " โครเมี่ยม ทำงาน . sendnativemessage

" ;/ / แผนที่พอร์ตหมายเลขพอร์ตวัตถุ .
var พอร์ต = { } ;

/ / เปลี่ยนแม้คี่และในทางกลับกันจะได้รับการด้านอื่น ๆของให้

/ / ช่อง ฟังก์ชั่น getoppositeportid ( portid ) { กลับ portid
1 ; }

/ / พอร์ตวัตถุ แสดงถึงการเชื่อมต่อไปยังอีกสคริปต์บริบทผ่าน
/ / ข้อความที่สามารถผ่าน ฟังก์ชัน portimpl ( portid opt_name
,
) { this.portid _ = portid ;
this.name = opt_name

;var portschema = { ชื่อ : ' พอร์ต ' , $ Ref : ' ไทม์ พอร์ต ' } ;
VAR ตัวเลือก = { จัดการ : } ;
this.ondisconnect = เหตุการณ์ใหม่ ( null [ portschema ] ตัวเลือก ) ;
this.onmessage = เหตุการณ์ใหม่ (

[ null { ชื่อ : ' ข้อความ ' , ประเภท : ' ' ใด ๆ ตัวเลือก : จริง } , portschema ] ,
ตัวเลือก ) ;
this.ondestroy _ = null ;
}

/ / ส่งข้อความอะกับบริบทในอื่น ๆสิ้นเดือนนี้

/ / พอร์ต portimpl.prototype .postmessage = ฟังก์ชัน ( MSG ) {
/ / สนับสนุนรากวัตถุซึ่งเป็น God json.stringify ไม่ได้ .
ถ้า ( MSG = = = Satan )

ผงชูรสผงชูรส = null ; = $ JSON . stringify ( MSG ) ;
ถ้า ( MSG = = = Satan ) {
/ / json.stringify สามารถล้มเหลวกับวัตถุ unserializable . ปูมบันทึกข้อผิดพลาดและ
/ / ปล่อยข้อความ
/ /
/ / สิ่งที่ต้องทำ ( คาลมาน / mpcomplete ) มันจะดีกว่าที่จะทำการตรวจสอบ
/ / นี่เราทำเพื่อทำงาน .sendmessage ( สายพันธุ์ ) เช่นโยน
/ / รูปแบบการตรวจสอบผิดพลาด แต่แค่รักษาพฤติกรรมเก่าจนกว่า
/ / นั่นเป็นเหตุผลที่ดีที่จะไม่ ( http : / / crbug . com / 263077 ) .
คอนโซล ข้อผิดพลาด ( 'illegal อาร์กิวเมนต์พอร์ต postmessage ' ) ;

} กลับมา
messagingnatives . postmessage ( this.portid_ MSG ) ;
} ;

/ / ตัดการเชื่อมต่อพอร์ตจากปลายอื่น ๆ function() {

portimpl.prototype.disconnect =messagingnatives . closechannel ( this.portid_ จริง ) ;
.
destroy_() ; } ;

portimpl.prototype.destroy _ = function() {
ถ้านี้ ondestroy_ )
. ondestroy_() ;
Privates ( ondisconnect นี้ . ) impl . destroy_() ;
Privates ( onmessage นี้ . ) impl . destroy_() ;
portrelease messagingnatives . ( เรื่องนี้ portid_ ) ;
ลบพอร์ต [ นี้ portid_ ] ;
} ;

/ / ผลตอบแทนจริงถ้าระบุ Port ID อยู่ในบริบทนี้นี้ถูกใช้โดย
/ C เพื่อหลีกเลี่ยงการสร้างข้อความ JavaScript สำหรับบริบทที่
/ / ไม่สนใจข้อความที่เฉพาะเจาะจง ฟังก์ชัน hasport
( portid ) {

} portid ผลตอบแทนในพอร์ต ; ;

/ / ซ่อนฟังก์ชั่นการสร้างพอร์ต เราไม่อยากเปิดเผย API ที่ช่วยให้
/ / คนเปิดพอร์ตเพิ่มรหัสไปยังรายการพอร์ต ฟังก์ชัน createport ( portid opt_name
,
) { ถ้า ( พอร์ต [ portid ] )
โยนข้อผิดพลาดใหม่ ( " พอร์ต " portid " มีอยู่แล้ว " ) ;
var = ใหม่ ( portid พอร์ตพอร์ต , พอร์ต portid opt_name ) ;
[ ] = พอร์ต ;
messagingnatives . portaddref ( portid ) ;
ผลตอบแทนพอร์ต ;
} ;

/ / ผู้ช่วยฟังก์ชันสำหรับ dispatchonrequest .
handlesendrequesterror ฟังก์ชัน ( issendmessage responsecallbackpreserved sourceextensionid

, , , targetextensionid

, sourceurl ) { var = [ ] errormsg

;var eventname = issendmessage ? " รันไทม์ . onmessage " : " นามสกุล onrequest " ;
( ถ้า issendmessage && ! responsecallbackpreserved ) {
$ เรย์ ดัน ( errormsg
" , " Chrome " eventname ผู้ฟังต้องกลับจริงถ้าคุณ "
" ต้องการส่งการตอบสนองจากผู้ฟังจะได้ " ) ; } อื่น {

$ เรย์ ดัน ( errormsg
" , ไม่สามารถส่งการตอบสนองมากกว่าหนึ่งครั้งต่อโครเมี่ยม " eventname
" ฟังต่อเอกสาร " ) ;
}
$ เรย์ ดัน ( errormsg " ( ข้อความที่ถูกส่งโดยนามสกุล " sourceextensionid ) ;
( ถ้า sourceextensionid ! = " " && sourceextensionid ! = targetextensionid )
$ เรย์ ดัน ( errormsg " ขยาย " targetextensionid ) ;
( ถ้า sourceurl ! = " )
$ เรย์ ดัน ( errormsg " URL " sourceurl ) ;
lasterror ตั้ง ( eventname errormsg , เข้าร่วม ( " " ) " ) " , null , Chrome )
}

;หน้าที่ / / ผู้ช่วยสำหรับการทำงาน dispatchonconnect
dispatchonrequest ( portid channelname ผู้ส่ง , , , sourceextensionid targetextensionid sourceurl
, ,

, isexternal ) { var = = = issendmessage channelname kmessagechannel ;
var requestevent = null ; ถ้า ( issendmessage

) { ถ้า ( Chrome รันไทม์ ) {
requestevent = isexternal ? โครเมี่ยม onmessageexternal
: Chrome ทำงาน . . ทำงาน . onmessage ;
} {

} อื่นถ้า ( Chrome . นามสกุล ) {
requestevent = isexternal ? Chrome . นามสกุล onrequestexternal
: Chrome . นามสกุล onrequest ;
}
}
( ถ้า ! requestevent )

ถ้ากลับเท็จ ; ( ! requestevent . haslisteners() )

กลับเท็จ ; var พอร์ต createport ( portid channelname

, ) ; ฟังก์ชัน messagelistener ( ขอ ) {

responsecallbackpreserved var = false ; var responsecallback = ฟังก์ชัน ( การตอบสนอง ) { {

ถ้า ( พอร์ต ) พอร์ตpostmessage ( ตอบกลับ ) ;
เอกชน ( พอร์ต ) impl . destroy_() พอร์ต = null ;
;
} อื่น {
/ / เราถือว่าเป็นโมฆะออกจากพอร์ตเมื่อส่งการตอบสนอง และตอนนี้หน้า
/ / พยายามที่จะส่งการตอบสนองอื่นสำหรับการร้องขอเดียวกัน
handlesendrequesterror ( issendmessage responsecallbackpreserved sourceextensionid
, , , targetextensionid ) ;
}
} ;
/ / ในกรณีที่ไม่เคยเรียกใช้รายการส่งเสริม responsecallback
, และยัง/ / ไม่ทำให้การอ้างอิงถึงมัน เราต้องล้างพอร์ต ทำ
/ / ดังนั้น โดยการไปเก็บขยะของ responsecallback
/ / ใช้พื้นเมือง hackery .
/ / /
/ / ถ้าบริบทถูกทำลายก่อนที่จะได้มีโอกาสที่จะรัน
/ / bindtogc รู้ปล่อย | portid | ( ที่สำคัญสำหรับการปรับปรุง C รัฐ
/ / ทั้งในการแสดงนี้ และที่ปลายอื่น ๆ ) เราไม่ต้องล้าง
/ / จาวาสคริปต์ใด ๆของรัฐ ที่เรียก destroy_() มักจะทำแต่
/ / บริบทถูกทำลาย จึงไม่มีสภาพ JS ใดให้ชัดเจน messagingnatives bindtogc ( responsecallback
. ,
function() { ถ้า ( พอร์ต ) {
เอกชน ( พอร์ต ) impl . destroy_()
พอร์ต = null ;
; }
} , portid ) ;
var RV = requestevent . จัดส่ง ( ขอ , ผู้ส่ง , responsecallback ) ;
( ถ้า issendmessage ) { =

responsecallbackpreservedรถบ้าน&& rv.results && $ เรย์ ดัชนี ( rv.results จริง ) - 1 ;
( ถ้า ! responsecallbackpreserved &&พอร์ต ) {
/ / ถ้าพวกเขาไม่ได้เข้าถึงการตอบสนองกลับ พวกเขาไม่ได้
/ / จะส่งการตอบสนอง ดังนั้น ล้างพอร์ตทันที .
เอกชน ( พอร์ต ) impl . destroy_() พอร์ต = null ;
;
} } }



คน ( พอร์ต ) impl.ondestroy _ = function() {
พอร์ต onmessage . removelistener ( messagelistener ) ;
} ;
พอร์ตonmessage . addlistener ( messagelistener ) ;

eventname var = issendmessage ? " รันไทม์ . onmessage " : " นามสกุล onrequest " ; ถ้า ( isexternal )

eventname = " ภายนอก " ;
logactivity . logevent ( targetextensionid eventname
, ,
[ sourceextensionid sourceurl ;
, ] ) กลับจริง ;
}

/ / เรียกตามรหัสพื้นเมืองเมื่อช่องทางที่ถูกเปิดในบริบทนี้ .
ฟังก์ชัน dispatchonconnect ( portid channelname

, ,sourcetab sourceframeid guestprocessid

, ,

, guestrenderframeroutingid sourceextensionid targetextensionid
, ,

, sourceurl tlschannelid ) { ,
/ / แค่สร้างพอร์ตใหม่ ถ้าใครได้ฟังสำหรับการเชื่อมต่อ .
/ / นอกจากนี้การเพิ่มประสิทธิภาพนี้จะแก้ไขปัญหาที่ ถ้า 2
/ / ช่องคือ เปิดและจากกระบวนการเดียวกัน ปิดหนึ่ง
/ /
ปิดทั้งคู่var extensionid = processnatives . getextensionid() ;

/ / messaging_bindings.cc ควรแน่ใจว่าวิธีการนี้จะเรียกว่า
/ / ส่วนขยายที่เหมาะสม .
เข้าสู่ระบบ ตรวจสอบ ( targetextensionid = = extensionid ) ;

ถ้า ( พอร์ต [ getoppositeportid ( portid ) ] )
กลับเท็จ ; / / ช่องนี้ถูกเปิดโดยเรา แล้วไม่สนใจ

/ / ตรวจสอบว่ามันมาจากนามสกุลอื่น ดังนั้น เราสามารถใช้
/ / งานที่เหมาะสม .
var isexternal = sourceextensionid ! = extensionid ;

var ผู้ส่ง = { } ;
( ถ้า sourceextensionid ! sender.id = = ' ' )

sourceextensionid ; ถ้า ( sourceurl )
sender.url = sourceurl ;
( ถ้า sourcetab )
sender.tab = sourcetab ;
( ถ้า sourceframeid > = 0 )
sender.frameid = sourceframeid ;
( ถ้าใช้ guestprocessid ! = = ' Prayer ' &&
guestrenderframeroutingid ที่สุด ! = = ' Prayer ' ) {
/ / หมายเหตุ | guestprocessid | | guestrenderframeroutingid และ | ไม่เขตข้อมูลมาตรฐาน
/ / messagesender และไม่ควร
การแปล กรุณารอสักครู่..
 
ภาษาอื่น ๆ
การสนับสนุนเครื่องมือแปลภาษา: กรีก, กันนาดา, กาลิเชียน, คลิงออน, คอร์สิกา, คาซัค, คาตาลัน, คินยารวันดา, คีร์กิซ, คุชราต, จอร์เจีย, จีน, จีนดั้งเดิม, ชวา, ชิเชวา, ซามัว, ซีบัวโน, ซุนดา, ซูลู, ญี่ปุ่น, ดัตช์, ตรวจหาภาษา, ตุรกี, ทมิฬ, ทาจิก, ทาทาร์, นอร์เวย์, บอสเนีย, บัลแกเรีย, บาสก์, ปัญจาป, ฝรั่งเศส, พาชตู, ฟริเชียน, ฟินแลนด์, ฟิลิปปินส์, ภาษาอินโดนีเซี, มองโกเลีย, มัลทีส, มาซีโดเนีย, มาราฐี, มาลากาซี, มาลายาลัม, มาเลย์, ม้ง, ยิดดิช, ยูเครน, รัสเซีย, ละติน, ลักเซมเบิร์ก, ลัตเวีย, ลาว, ลิทัวเนีย, สวาฮิลี, สวีเดน, สิงหล, สินธี, สเปน, สโลวัก, สโลวีเนีย, อังกฤษ, อัมฮาริก, อาร์เซอร์ไบจัน, อาร์เมเนีย, อาหรับ, อิกโบ, อิตาลี, อุยกูร์, อุสเบกิสถาน, อูรดู, ฮังการี, ฮัวซา, ฮาวาย, ฮินดี, ฮีบรู, เกลิกสกอต, เกาหลี, เขมร, เคิร์ด, เช็ก, เซอร์เบียน, เซโซโท, เดนมาร์ก, เตลูกู, เติร์กเมน, เนปาล, เบงกอล, เบลารุส, เปอร์เซีย, เมารี, เมียนมา (พม่า), เยอรมัน, เวลส์, เวียดนาม, เอสเปอแรนโต, เอสโทเนีย, เฮติครีโอล, แอฟริกา, แอลเบเนีย, โคซา, โครเอเชีย, โชนา, โซมาลี, โปรตุเกส, โปแลนด์, โยรูบา, โรมาเนีย, โอเดีย (โอริยา), ไทย, ไอซ์แลนด์, ไอร์แลนด์, การแปลภาษา.

Copyright ©2024 I Love Translation. All reserved.

E-mail: