Return-Path: X-Original-To: apmail-cordova-dev-archive@www.apache.org Delivered-To: apmail-cordova-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 0631AD4AD for ; Tue, 28 May 2013 16:08:31 +0000 (UTC) Received: (qmail 5939 invoked by uid 500); 28 May 2013 16:08:30 -0000 Delivered-To: apmail-cordova-dev-archive@cordova.apache.org Received: (qmail 5843 invoked by uid 500); 28 May 2013 16:08:30 -0000 Mailing-List: contact dev-help@cordova.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cordova.apache.org Delivered-To: mailing list dev@cordova.apache.org Received: (qmail 5826 invoked by uid 99); 28 May 2013 16:08:29 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 28 May 2013 16:08:29 +0000 X-ASF-Spam-Status: No, hits=1.5 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of braden@google.com designates 209.85.214.54 as permitted sender) Received: from [209.85.214.54] (HELO mail-bk0-f54.google.com) (209.85.214.54) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 28 May 2013 16:08:25 +0000 Received: by mail-bk0-f54.google.com with SMTP id it16so3952924bkc.41 for ; Tue, 28 May 2013 09:08:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=fNXwtgs+bFiQ1Wd9fwpyKqSnswPW41klQjg8Mj4YjQw=; b=HwtKD3Cqqr/eTAZp+GD6zGipfoQpNhBLGi3k4Q0ixeRi7pWE4Tf6ZD6vdHf7Q8CNgs iNUwdQxsdnu+yILp5GVich2iyGkBvuGhn5w6+v2pofGk9phnPlu7JJHC50F2eb6WlWsG f+zkf+wNJZ+REbC9Rn9gpSUoIgihVyCKeVuNPPFmvIEdb1H5dwrd9g0PBLVJzQAXJWb1 TiluA4CoNPsoGU3iuFLKR4Ybd+xjFhdsTN/IAPRjIFOiPq0sjbgZIodjk9RHVC45gEYk l1gVXpMHHDlfbBfxZUltDpQCYNIexsDTFSo38KZyMzUd8Vlcn+gQaIkpSdmJy/I9qnnY M09Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:x-gm-message-state; bh=fNXwtgs+bFiQ1Wd9fwpyKqSnswPW41klQjg8Mj4YjQw=; b=Uhn+9rTt9bk5FuZNDrYusbcTzY0ubwuM3mPyDLMZ+cVJTbkoE5khKC8dPzs8kYR3Ld mnU2Fhk2VuyCDfWHe/yGdxKIvXtzceVdqSU1034yDR9DCyqNFhkUbwJrmH7B3O1BILjo edMnxu3g8QrkTfWVLGzf/HpjtpActi4eKRTIAv1qJShkaWqKxZFc4SpSbTC/cj2eliFr M9Mql2E/JentWdQi1dubuUqW/oMJYrXlOyvtBGYyUHL0ZndJ3Thr3uw/g9Tb7y0zTuVB yZwRFbsOwkfhpwUbcij3nes5JE1UBFBScvb0SrA6Z1DfofwYGd7STxUWAE5zcKeSBaq2 4Kqg== MIME-Version: 1.0 X-Received: by 10.204.240.139 with SMTP id la11mr846997bkb.56.1369757284286; Tue, 28 May 2013 09:08:04 -0700 (PDT) Received: by 10.205.112.132 with HTTP; Tue, 28 May 2013 09:08:04 -0700 (PDT) In-Reply-To: <71D9CE88E9AC0C4F8C91CE1D3D4DC99301FAF299@DEWDFEMB18A.global.corp.sap> References: <71D9CE88E9AC0C4F8C91CE1D3D4DC99301FAF299@DEWDFEMB18A.global.corp.sap> Date: Tue, 28 May 2013 12:08:04 -0400 Message-ID: Subject: Re: inAppBrowser API issue From: Braden Shepherdson To: "Li, Jonathan" Cc: "dev@cordova.apache.org" Content-Type: multipart/alternative; boundary=20cf303346d75c126f04ddc9783d X-Gm-Message-State: ALoCoQmtMX0x7o7cRrqZpr1fIsWa7GcZsK2Srtfz7VODqS7YOyEOzdu+n5Ty+trUC7IS0cST3ewt0ndy2uvgn2vEs3TVr2LKOMKywWGkq5pO1qA2ObIib4WdL40iLo32eia6lpbr4qXXltGHers+hGP1sJM5aGR4nBstcgZmdIZgtRq5NOET8IYxKXizk2UsAYk6cCn/Ko6j X-Virus-Checked: Checked by ClamAV on apache.org --20cf303346d75c126f04ddc9783d Content-Type: text/plain; charset=ISO-8859-1 This is not an accident of Javascript implementations that we're relying on. It is absolutely essential and fully specified that Javascript engines have this async behavior. One task completes before any others run. The handling of onError is our responsibility; I assume that our code uses setTimeout(..., 0); to enqueue the error in a new task, and give the user code a chance to add handlers. Take a look at the (standard) IndexedDB API; it is packed with this style. Braden On Tue, May 28, 2013 at 12:04 PM, Li, Jonathan wrote: > It is a little bit different from window.open defined by w3c. As > window.open, the onload, onerror events can be embedded in the html page, > they will be automatically attached to DOM when parsing the page, there is > no need to add the event handler by separate calls, so no event will be > missed. > > In fact, if calling the similar code shown below on a regular page, the > onload method will not be called. > > var ref = window.open('http://apache.org'); > ref.addEventListener('loadstart', function() { alert(event.url); }); > > > The design should not heavily depend on the current browser's javascript > thread implementation. Besides it is not safe to always assume the event > will only be fired asynchronously from native code. For example, if invalid > parameters are passed to open method, the validator may need to call > onError to report the error, it will not work if onError event handler > cannot be added before the operation. > > Jonathan > > > -----Original Message----- > From: braden@google.com [mailto:braden@google.com] On Behalf Of Braden > Shepherdson > Sent: Tuesday, May 28, 2013 11:10 AM > To: dev@cordova.apache.org > Subject: Re: inAppBrowser API issue > > If the event really did fire before the event listener was added, the > Javascript engine is broken. When the event is triggered (which may happen > in another browser thread or something) it will be added to the event queue > in the Javascript engine. That event will not be processed until the > currently executing Javascript chunk is done - the next time the Javascript > cedes control (setTimeout, returning from all functions, etc.). That won't > happen until after the event handler is attached in the second line. > > We didn't design this API, it's the same window.open API is is used > elsewhere. Cordova tends to use existing W3C specs where appropriate. > > Braden > > > On Tue, May 28, 2013 at 10:47 AM, Li, Jonathan > wrote: > > > Not sure whether this is a right place for this issue, but the javascript > > interface for InAppBrowser does not make much sense. The below code is > > from cordova document: > > > > var ref = window.open('http://apache.org', '_blank', 'location=yes'); > > ref.addEventListener('loadstart', function() { alert(event.url); }); > > > > The event handler is added after the open method is returned, so it is > > possible the event gets fired before developer has a chance to add the > > event handler for the open operation. Although it is async operation, it > > is still a good design, and may cause timing or other issues depending on > > native side implementation. > > > > Just wonder whether this is a known issue, or could it be changed to a > > better interface design? > > > > Thanks > > Jonathan > > > > > --20cf303346d75c126f04ddc9783d--