Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(206558)

Unified Diff: Lib/webbrowser.py

Issue 23670: Modifications to support iOS as a development platform
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Lib/unittest/test/test_runner.py ('k') | Modules/_ctypes/libffi_ios/aarch64/ffi_arm64.c » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
--- a/Lib/webbrowser.py Tue Mar 01 10:26:10 2016 +0200
+++ b/Lib/webbrowser.py Wed Mar 02 00:01:35 2016 +0000
@@ -597,16 +597,67 @@ if sys.platform == 'darwin':
# Don't clear _tryorder or _browsers since OS X can use above Unix support
# (but we prefer using the OS X specific stuff)
register("safari", None, MacOSXOSAScript('safari'), -1)
register("firefox", None, MacOSXOSAScript('firefox'), -1)
register("MacOSX", None, MacOSXOSAScript('default'), -1)
+#
+# Platform support for iOS
+#
+if sys.platform == 'ios':
+ class MobileSafari(BaseBrowser):
+ def open(self, url, new=0, autoraise=True):
+ # This code is the equivalent of:
+ # NSURL *nsurl = [NSURL URLWithString:url];
+ # [[UIApplication sharedApplication] openURL:nsurl];
+ from ctypes import cdll, c_void_p, c_char_p, c_uint32
+ from ctypes import util
+ objc = cdll.LoadLibrary(util.find_library(b'objc'))
+ cf = cdll.LoadLibrary(util.find_library(b'CoreFoundation'))
+ objc.objc_getClass.restype = c_void_p
+ objc.objc_getClass.argtypes = [c_char_p]
+ objc.sel_registerName.restype = c_void_p
+ objc.sel_registerName.argtypes = [c_char_p]
+ cf.CFStringCreateWithCString.restype = c_void_p
+ cf.CFStringCreateWithCString.argtypes = [c_void_p, c_char_p, c_uint32]
+
+ # Get an NSString describing the URL
+ kCFStringEncodingUTF8 = 0x08000100
+ url = c_void_p(cf.CFStringCreateWithCString(None, url.encode('utf-8'), kCFStringEncodingUTF8))
+ autorelease = c_void_p(objc.sel_registerName(b'autorelease'))
+ objc.objc_msgSend.argtypes = [c_void_p, c_void_p]
+ objc.objc_msgSend.restype = c_void_p
+ objc.objc_msgSend(url, autorelease)
+
+ # Get an NSURL object representing the URL
+ NSURL = c_void_p(objc.objc_getClass(b'NSURL'))
+ urlWithString_ = c_void_p(objc.sel_registerName(b'URLWithString:'))
+ objc.objc_msgSend.restype = c_void_p
+ objc.objc_msgSend.argtypes = [c_void_p, c_void_p, c_void_p]
+ nsurl = c_void_p(objc.objc_msgSend(NSURL, urlWithString_, url))
+
+ # Get the shared UIApplication instance
+ UIApplication = c_void_p(objc.objc_getClass(b'UIApplication'))
+ sharedApplication = c_void_p(objc.sel_registerName(b'sharedApplication'))
+ objc.objc_msgSend.argtypes = [c_void_p, c_void_p]
+ objc.objc_msgSend.restype = c_void_p
+ shared_app = c_void_p(objc.objc_msgSend(UIApplication, sharedApplication))
+
+ # Open the URL on the shared application
+ openURL_ = c_void_p(objc.sel_registerName(b'openURL:'))
+ objc.objc_msgSend.argtypes = [c_void_p, c_void_p, c_void_p]
+ objc.objc_msgSend.restype = None
+ objc.objc_msgSend(shared_app, openURL_, nsurl)
+
+ return True
+
+ register("mobilesafari", None, MobileSafari(), -1)
# OK, now that we know what the default preference orders for each
# platform are, allow user to override them with the BROWSER variable.
if "BROWSER" in os.environ:
_userchoices = os.environ["BROWSER"].split(os.pathsep)
_userchoices.reverse()
# Treat choices in same way as if passed into get() but do register
« no previous file with comments | « Lib/unittest/test/test_runner.py ('k') | Modules/_ctypes/libffi_ios/aarch64/ffi_arm64.c » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+