News for hackers. Stuff that matters.
Re:Open-sourcing Chrome on iOS by wadetandy on Tuesday January 31, 2017 @01:37PM (#13533686)
My understanding is that the reason Chrome has to use the iOS webkit view is because that's the only way to get JIT javascript compilation working for apps submitted to the app store. Does anyone have a sense of whether it would be possible to switch to Blink and V8 with a locally compiled and sideloaded version of the app? Would there be any benefit?
Re:Open-sourcing Chrome on iOS by zwily on Tuesday January 31, 2017 @01:48PM (#13533835)
You're not allowed to provide your own web render engine at all. The JIT issue was solved a couple versions of iOS ago - embedded webviews now get JIT just like Safari.
Re:Open-sourcing Chrome on iOS by DonHopkins on Tuesday January 31, 2017 @02:28PM (#13534298)
It's my understanding that only embedded WKWebViews are allowed to enable the JIT compiler, but not UIWebViews (or in-process JavaScriptCore engines). WKWebView is an out-of-process web browser that uses IOSurface [1] to project the image into your embedding application and IPC to send messages.

So WKWebView's dynamically generated code is running safely firewalled in a separate address space controlled by Apple and not accessible to your app, while older UIWebViews run in the address space of your application, and aren't allowed to write to code pages, so their JIT compiler is disabled.

Since it's running in another process, WkWebView's JavaScriptEngine lacks the ability to expose your own Objective C classes to JavaScript so they can be called directly [2], but it does include a less efficient way of adding script message handlers that call back to Objective C code via IPC [3].

[1] https://developer.apple.com/reference/iosurface

[2] https://developer.apple.com/reference/javascriptcore/jsexpor...

[3] https://developer.apple.com/reference/webkit/wkusercontentco...

Re:Open-sourcing Chrome on iOS by eslaught on Tuesday January 31, 2017 @02:58PM (#13534615)
> You're not allowed to provide your own web render engine at all.

Is that true? I understand the security argument against JITs, but I don't see why it would be objectionable to run a copy of e.g. Gecko if you excluded the JS JIT component. (Of course you would never actually do that. But I'm trying to tease apart the separate arguments and see if they're actually connected.)

It seems to me that the root cause for this is all the JIT. If the JIT in iOS has to be exposed via IPC for security (as claimed in a sibling comment) it's simply not going to be a win to try to use it in combination with a separate rendering engine, if it's even possible at all.

Re:Open-sourcing Chrome on iOS by bzbarsky on Tuesday January 31, 2017 @03:32PM (#13534911)
You're not allowed to ship a interpreter that interprets code that doesn't come from insider your app.

So you can maybe ship Gecko + SpiderMonkey, as long as you only run JS that's part of your app. But if you want to run JS from a website (or indeed any code from anywhere), you're not allowed to do that on iOS.

I haven't checked whether it would be OK to ship a browser engine that doesn't support JS at all, but that's a fairly academic question anyway.

Re:Open-sourcing Chrome on iOS by eslaught on Tuesday January 31, 2017 @07:29PM (#13536924)
But for example, could you ship Gecko with Apple's JS engine in a way that will satisfy Apple's requirements? Of course the answer is no, but it's worth taking a second to think about why that is.

I guess what's bothering me is that there is an unstated assumption underlying this entire discussion which people never bring up: for performance reasons, the rendering engine has to be tied closely to the JS implementation. Specifically, calling over some IPC interface at every entrypoint into the JS interpreter would be a performance nightmare. This is the reason why these can't be disentangled. The connection to the interpreter is really an indirect one.

Re:Open-sourcing Chrome on iOS by st3fan on Tuesday January 31, 2017 @03:58PM (#13535153)
> You're not allowed to ship a interpreter that interprets code that doesn't come from insider your app.

That is not true. Many apps do this. Games have been doing this for a decade. It is not a problem to do this. Apple has never made a big deal of that. Only if you are trying to build a shadow app store.

Re:Open-sourcing Chrome on iOS by wvenable on Tuesday January 31, 2017 @04:09PM (#13535251)
Games interpret code that's shipped with the app. You cannot create an app which downloads code off the Internet (for example) and executes it.
Re:Open-sourcing Chrome on iOS by st3fan on Tuesday January 31, 2017 @04:21PM (#13535356)
Games and apps have been doing this for a decade.

Apple does not care. As long as you are operating in the spirit of their App Store.

You know when they care? When you start charging money for those downloads. Via an alternative payment channel. Or when you run an alternative app store from within your app.

If you download assets on demand, and some of those turn out to be executable* code, nobody cares.

* Where executable means 'interpreted' because you cannot run unsigned code. But for games that is fine, they have been doing this with JS, Lua and Python for a decade.

(You can downvote me - but this is based on a decade of experience)

Re:Open-sourcing Chrome on iOS by wvenable on Tuesday January 31, 2017 @05:27PM (#13535913)
They do care; Apple has shut down (or restricted) several apps over the years that have tried this. But I ultimately agree with you, it's really more about how it's presented rather than how it works under the hood. This might have a lot to do with the review process.

The subject we're talking about here would not fly under their radar.

Re:Open-sourcing Chrome on iOS by bzbarsky on Wednesday February 01, 2017 @02:48PM (#13544313)
What you're saying is that Apple is inconsistent in enforcing its officially stated policy. That may be true, but does not change what the official policy is and that they can enforce it any time they want to.
Re:Open-sourcing Chrome on iOS by solidr53 on Tuesday January 31, 2017 @07:52PM (#13537074)
not true, checkout codepush from microsoft which enables OTA updates for cordova, react native, etc.
Re:Open-sourcing Chrome on iOS by ec109685 on Wednesday February 01, 2017 @01:29AM (#13538772)
Yeah, because JavaScript is exempted from their rules.
Re:Open-sourcing Chrome on iOS by bzbarsky on Monday February 06, 2017 @11:29AM (#13581022)
JavaScript in general, or JavaScript only if it's run via Apple's JavaScriptCore?
Re:Open-sourcing Chrome on iOS by wvenable on Sunday February 12, 2017 @07:29PM (#13632125)
JavaScript only if it's run via Apple's JavaScriptCore.

Pebble used this quite effectively to add phone-side apps to their product.

Re:Open-sourcing Chrome on iOS by tiles on Tuesday January 31, 2017 @10:32PM (#13537989)
See Microsoft CodePush and React Native for a counterexample: you can certainly publish apps which download code as long as they don't dramatically alter the functionality of the app.
Re:Open-sourcing Chrome on iOS by madeofpalk on Tuesday January 31, 2017 @04:09PM (#13535261)
Games are a specific exemption to this rule.
Re:Open-sourcing Chrome on iOS by st3fan on Tuesday January 31, 2017 @03:30PM (#13534897)
> Is that true?

It is. Mozilla has an iOS port of Gecko. It runs well, even without the JIT, but we are not allowed to use it.

Re:Open-sourcing Chrome on iOS by Ezhik on Tuesday January 31, 2017 @03:59PM (#13535171)
Is that OSS? I'm sure people would love to try it even if it involves sideloading and such.
Re:Open-sourcing Chrome on iOS by st3fan on Tuesday January 31, 2017 @04:15PM (#13535302)
Pretty sure all the changes are in mozilla-central.

https://hg.mozilla.org/mozilla-central/file/tip/embedding/io...

Sorry I dont know where we keep the build instructions.

Re:Open-sourcing Chrome on iOS by kalleboo on Wednesday February 01, 2017 @12:44AM (#13538580)
https://developer.apple.com/app-store/review/guidelines/

> 2.5.6 Apps that browse the web must use the appropriate WebKit framework and WebKit Javascript.

Re:Open-sourcing Chrome on iOS by therealmarv on Tuesday January 31, 2017 @03:09PM (#13534727)
take a close look at Opera Mini ;) (they are doing Server rendering)
Re:Open-sourcing Chrome on iOS by bad_user on Tuesday January 31, 2017 @01:47PM (#13533810)
Before iOS 9 (or something) that JIT engine wasn't even exposed in the web view available for apps, so no matter what you did, you couldn't match the performance of Safari.

On iOS browsers like Chrome and Firefox are basically unable to compete in terms of performance, web standards or features like browser plugins. So people that use them do so just to get sync. Of course Safari Mobile is decent nowadays, but that's not the issue.

Re:Open-sourcing Chrome on iOS by oatmealsnap on Tuesday January 31, 2017 @01:49PM (#13533841)
Yea, it was always an outdated version of WebKit.
Re:Open-sourcing Chrome on iOS by JonathonW on Tuesday January 31, 2017 @01:56PM (#13533919)
Not outdated (it's always been the same WebKit version as used by Safari), but security restrictions on iOS (specifically, third-party iOS apps can't JIT-- the OS won't let apps without a specific entitlement execute from a writable section of memory) prevented in-app web views from using the same Javascript engine as Safari.

iOS 9 eliminated that performance penalty-- it introduced a new kind of web view backed by an out-of-process renderer and JS engine, which, since it's Apple-blessed, doesn't have the JIT restriction. Third-party browsers updated to use the new framework can get the same performance as Safari.

Re:Open-sourcing Chrome on iOS by gcp on Tuesday January 31, 2017 @02:15PM (#13534164)
Third-party browsers updated to use the new framework can get the same performance as Safari.

But that framework is missing various things, such as content blocking. (That goes a long way to explain why there's both "Focus" and "Firefox" on iOS)

Re:Open-sourcing Chrome on iOS by djrogers on Tuesday January 31, 2017 @02:37PM (#13534406)
> But that framework is missing various things, such as content blocking

Not really - SFSafariViewController uses content blockers, autofill, etc. There's also WKWebView for those that want to implement their own content blockers and autofill engines.

Curious why you'd want safari's content blockers to run inside chrome or firefox though? That's not how browser plugins work anywhere else, and it seems like if content blockers were forced in to 3rd party browsers there'd be a lot more angst over that decision.

[1] https://developer.apple.com/library/ios/documentation/Safari...

Re:Open-sourcing Chrome on iOS by st3fan on Tuesday January 31, 2017 @03:42PM (#13534995)
> Curious why you'd want safari's content blockers to run inside chrome or firefox though?

Because WKWebView has such a limited API that it currently is impossible to implement content blocking.

WKWebView is both a blessing and a curse for browsers like Chrome and Firefox.

A blessing because tt works really well inside that square area where content is rendered. It is as fast as Safari, as responsive to touch gestures, supports web APIs pretty well.

A curse because the API that it exposes is completely lacking. No way to intercept network requests, no way to interact with the DOM, no way to interact with JavaScript, no way to customize it fully, no way to do proper session store/restore, no way to interact with its internal caches, no way to set the cookie policy, no way to customize the context menus that it exposes, no way to handle errors better, no way to set headers on requests, no way to use content filters ..

I can go on for a while. You can look at the Chrome and Firefox source code to understand the crazy workaround both browsers had to do to get some pretty basic functionality.

Search for WKWebView on https://bugz.webkit.org to see what people have been asking for, for the past three years.

Re:Open-sourcing Chrome on iOS by gcp on Tuesday January 31, 2017 @02:41PM (#13534440)
Curious why you'd want safari's content blockers to run inside chrome or firefox though? That's not how browser plugins work anywhere else

Because there's currently no way for those browsers to get any content blocking without switching to the slower WebView.

I'm fairly confident that both the Google Chrome team and Mozilla's Firefox for iOS team are better informed here than you are.

Re:Open-sourcing Chrome on iOS by st3fan on Tuesday January 31, 2017 @03:48PM (#13535060)
Not sure why this is downvoted because gcp is correct.

Apple has decided that Content Blocking is a Safari only feature. Apple has made the decision to not expose the private APIs in WKWebView that would allow browsers like Chrome and Firefox to use the same speedy content blocking.

The old WebView, UIWebView, also does not support content blocking. But since it runs completely in the same process as your app, you can replace the HTTP handling with your own and patch content blocking on top of that.

That is what Firefox Focus and Brave do for example. It works, but it is far from ideal. Also, it is likely an API on the way to be deprecated.

Re:Open-sourcing Chrome on iOS by st3fan on Tuesday January 31, 2017 @03:32PM (#13534919)
> Not really - SFSafariViewController uses content blockers, autofill, etc.

SFSafariViewController is useles for apps like Chrome and Firefox. It is an embedded Safari controller. Not an embedded generic webview controller.

SFSafariViewController has zero API. All it can do is display a webpage. Applications that use it have zero ability to even modify the UI.

That is intentional. It is supposed to be a Safari view. And for security reasons that is probabl good, otherwise it would be a gateway to your browsing data.

Re:Open-sourcing Chrome on iOS by bad_user on Tuesday January 31, 2017 @02:41PM (#13534437)
Extensions like 1Password work in Firefox and Chrome but not content blockers. I know because I tested both.

Mozilla also made a statement about it: https://motherboard.vice.com/read/heres-why-firefox-for-ios-...

Re:Open-sourcing Chrome on iOS by st3fan on Tuesday January 31, 2017 @03:44PM (#13535020)
1Password only works in non-Safari browsers if those apps include a less optimal SDK that provides a generic password filling conduit.

It is not something that WKWebView automagically does.

See https://github.com/AgileBits/onepassword-app-extension

Re:Open-sourcing Chrome on iOS by hendersoon on Tuesday January 31, 2017 @02:42PM (#13534449)
SFSafariViewController essentially IS safari. It isn't appropriate for a third-party browser.

While it is technically possible to use content blockers in WKWebView, it can only be done via private APIs, and Apple capriciously bans apps from their appstore that use private APIs.

Reference: https://bugs.webkit.org/show_bug.cgi?id=150479

Re:Open-sourcing Chrome on iOS by hendersoon on Tuesday January 31, 2017 @02:36PM (#13534397)
Exactly right. Lack of content blocking is why I don't use Chrome on iOS. I strongly prefer its UI and sync, but can't go back to seeing ads.
Re:Open-sourcing Chrome on iOS by spikengineer on Tuesday January 31, 2017 @02:33PM (#13534365)
If you don't use Apple Webkit view apple doesn't even allow you put your browser on the appstore. All other browser engines are banned.

See section 2.5.6 of the Appstore guidelines

"2.5.6 Apps that browse the web must use the appropriate WebKit framework and WebKit Javascript."

https://developer.apple.com/app-store/review/guidelines/

Re:Open-sourcing Chrome on iOS by rweichler on Tuesday January 31, 2017 @04:13PM (#13535291)
No. You can't map executable pages in the sandbox. JITs (such as LuaJIT) only work while the debugger is attached (i.e., you open the app by clicking "run" in Xcode).
Re:Open-sourcing Chrome on iOS by therealmarv on Tuesday January 31, 2017 @03:08PM (#13534713)
Opera Mini bypasses this restriction with doing Server Rendering. I wonder why Apple is ok with them (because it'a a big security risk to server render HTTPS IMHO).

And regarding your quesiton: I'm sure you cannot replace their webkit usage with one switch to Blink... I'm sure the iOS internal webview is deeply integrated/

Re:Open-sourcing Chrome on iOS by abrowne on Tuesday January 31, 2017 @03:29PM (#13534887)
Opera Mini, the app, is not rendering HTML as you say. They don't block VNC or RDP apps even though you can run a remote browser through them.
Re:Open-sourcing Chrome on iOS by oatmealsnap on Tuesday January 31, 2017 @01:48PM (#13533823)
That might allow Chrome Extensions on iOS, but it seems like a lot of work to make that happen.
Re:Open-sourcing Chrome on iOS by madeofpalk on Tuesday January 31, 2017 @04:08PM (#13535248)
> locally compiled

You can't "locally compile" code on iOS. That's against App Store guidelines.

Re:Open-sourcing Chrome on iOS by hawski on Tuesday January 31, 2017 @04:23PM (#13535369)
I am sure that he meant "locally" as on one's one computer without AppStore.