def webview_should_start_load(self, webview, url, nav_type):
# Click, should start edit in markdown
if url.startswith(self.link_prefix):
left_side = unquote(url.replace(self.link_prefix, ''))
self.start_editing(left_side.split())
#webview.stop()
return False
# Debug message from web page, print to console
elif url.startswith(self.debug_prefix):
debug_text = unquote(url.replace(self.debug_prefix, ''))
print debug_text
return False
# Loaded by the web view at start, allow
elif url.startswith('about:blank'):
return True
# Custom WebView initialization message
# Used to check if in-doc links starting with '#'
# have extra stuff in front
elif url.endswith(self.init_postfix):
self.in_doc_prefix = url[:len(url)-len(self.init_postfix)]
self.web.hidden = False
return False
# If link starts with the extra stuff detected
# at initialization, remove the extra
if url.startswith(self.in_doc_prefix):
url = url[len(self.in_doc_prefix):]
# Check for custom link handling
if self.can_call('webview_should_start_load'):
return self.proxy_delegate.webview_should_start_load(webview, url, nav_type)
# Handle in-doc links within the page
elif url.startswith('#'):
if self.can_call('webview_should_load_internal_link'):
return self.proxy_delegate.webview_should_load_internal_link(webview, url)
return True
# Open 'http(s)' links in Safari
# 'file' in built-in browser
# Others like 'twitter' as OS decides
else:
if self.can_call('webview_should_load_external_link'):
return self.proxy_delegate.webview_should_load_external_link(webview, url)
if url.startswith('http:') or url.startswith('https:'):
url = 'safari-' + url
webbrowser.open(url)
return False
评论列表
文章目录