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

Side by Side Diff: Lib/webbrowser.py

Issue 23670: Modifications to support iOS as a development platform
Patch Set: Created 3 years, 8 months ago
Left:
Right:
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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #! /usr/bin/env python3 1 #! /usr/bin/env python3
2 """Interfaces for launching and remotely controlling Web browsers.""" 2 """Interfaces for launching and remotely controlling Web browsers."""
3 # Maintained by Georg Brandl. 3 # Maintained by Georg Brandl.
4 4
5 import os 5 import os
6 import shlex 6 import shlex
7 import shutil 7 import shutil
8 import sys 8 import sys
9 import subprocess 9 import subprocess
10 10
(...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 rc = osapipe.close() 595 rc = osapipe.close()
596 return not rc 596 return not rc
597 597
598 598
599 # Don't clear _tryorder or _browsers since OS X can use above Unix support 599 # Don't clear _tryorder or _browsers since OS X can use above Unix support
600 # (but we prefer using the OS X specific stuff) 600 # (but we prefer using the OS X specific stuff)
601 register("safari", None, MacOSXOSAScript('safari'), -1) 601 register("safari", None, MacOSXOSAScript('safari'), -1)
602 register("firefox", None, MacOSXOSAScript('firefox'), -1) 602 register("firefox", None, MacOSXOSAScript('firefox'), -1)
603 register("MacOSX", None, MacOSXOSAScript('default'), -1) 603 register("MacOSX", None, MacOSXOSAScript('default'), -1)
604 604
605 #
606 # Platform support for iOS
607 #
608 if sys.platform == 'ios':
609 class MobileSafari(BaseBrowser):
610 def open(self, url, new=0, autoraise=True):
611 # This code is the equivalent of:
612 # NSURL *nsurl = [NSURL URLWithString:url];
613 # [[UIApplication sharedApplication] openURL:nsurl];
614 from ctypes import cdll, c_void_p, c_char_p, c_uint32
615 from ctypes import util
616 objc = cdll.LoadLibrary(util.find_library(b'objc'))
617 cf = cdll.LoadLibrary(util.find_library(b'CoreFoundation'))
618 objc.objc_getClass.restype = c_void_p
619 objc.objc_getClass.argtypes = [c_char_p]
620 objc.sel_registerName.restype = c_void_p
621 objc.sel_registerName.argtypes = [c_char_p]
622 cf.CFStringCreateWithCString.restype = c_void_p
623 cf.CFStringCreateWithCString.argtypes = [c_void_p, c_char_p, c_uint3 2]
624
625 # Get an NSString describing the URL
626 kCFStringEncodingUTF8 = 0x08000100
627 url = c_void_p(cf.CFStringCreateWithCString(None, url.encode('utf-8' ), kCFStringEncodingUTF8))
628 autorelease = c_void_p(objc.sel_registerName(b'autorelease'))
629 objc.objc_msgSend.argtypes = [c_void_p, c_void_p]
630 objc.objc_msgSend.restype = c_void_p
631 objc.objc_msgSend(url, autorelease)
632
633 # Get an NSURL object representing the URL
634 NSURL = c_void_p(objc.objc_getClass(b'NSURL'))
635 urlWithString_ = c_void_p(objc.sel_registerName(b'URLWithString:'))
636 objc.objc_msgSend.restype = c_void_p
637 objc.objc_msgSend.argtypes = [c_void_p, c_void_p, c_void_p]
638 nsurl = c_void_p(objc.objc_msgSend(NSURL, urlWithString_, url))
639
640 # Get the shared UIApplication instance
641 UIApplication = c_void_p(objc.objc_getClass(b'UIApplication'))
642 sharedApplication = c_void_p(objc.sel_registerName(b'sharedApplicati on'))
643 objc.objc_msgSend.argtypes = [c_void_p, c_void_p]
644 objc.objc_msgSend.restype = c_void_p
645 shared_app = c_void_p(objc.objc_msgSend(UIApplication, sharedApplica tion))
646
647 # Open the URL on the shared application
648 openURL_ = c_void_p(objc.sel_registerName(b'openURL:'))
649 objc.objc_msgSend.argtypes = [c_void_p, c_void_p, c_void_p]
650 objc.objc_msgSend.restype = None
651 objc.objc_msgSend(shared_app, openURL_, nsurl)
652
653 return True
654
655 register("mobilesafari", None, MobileSafari(), -1)
605 656
606 # OK, now that we know what the default preference orders for each 657 # OK, now that we know what the default preference orders for each
607 # platform are, allow user to override them with the BROWSER variable. 658 # platform are, allow user to override them with the BROWSER variable.
608 if "BROWSER" in os.environ: 659 if "BROWSER" in os.environ:
609 _userchoices = os.environ["BROWSER"].split(os.pathsep) 660 _userchoices = os.environ["BROWSER"].split(os.pathsep)
610 _userchoices.reverse() 661 _userchoices.reverse()
611 662
612 # Treat choices in same way as if passed into get() but do register 663 # Treat choices in same way as if passed into get() but do register
613 # and prepend to _tryorder 664 # and prepend to _tryorder
614 for cmdline in _userchoices: 665 for cmdline in _userchoices:
(...skipping 27 matching lines...) Expand all
642 print(usage, file=sys.stderr) 693 print(usage, file=sys.stderr)
643 sys.exit(1) 694 sys.exit(1)
644 695
645 url = args[0] 696 url = args[0]
646 open(url, new_win) 697 open(url, new_win)
647 698
648 print("\a") 699 print("\a")
649 700
650 if __name__ == "__main__": 701 if __name__ == "__main__":
651 main() 702 main()
OLDNEW
« 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+