pub struct JavascriptResult(/* private fields */);
Implementations§
Source§impl JavascriptResult
impl JavascriptResult
Sourcepub fn global_context(&self) -> Option<GlobalContextRef>
pub fn global_context(&self) -> Option<GlobalContextRef>
Examples found in repository?
examples/main.rs (line 62)
34fn main() {
35 gtk::init().unwrap();
36
37 let window = Window::new(WindowType::Toplevel);
38 let context = WebContext::default().unwrap();
39 #[cfg(feature = "v2_4")]
40 context.set_web_extensions_initialization_user_data(&"webkit".to_variant());
41 context.set_web_extensions_directory("../webkit2gtk-webextension-rs/example/target/debug/");
42 #[cfg(feature = "v2_6")]
43 let webview = WebView::new_with_context_and_user_content_manager(&context, &UserContentManager::new());
44 #[cfg(not(feature = "v2_6"))]
45 let webview = WebView::with_context(&context);
46 webview.load_uri("https://crates.io/");
47 window.add(&webview);
48
49 let settings = WebViewExt::settings(&webview).unwrap();
50 settings.set_enable_developer_extras(true);
51
52 /*let inspector = webview.get_inspector().unwrap();
53 inspector.show();*/
54
55 window.show_all();
56
57 webview.run_javascript("alert('Hello');", None::<&gio::Cancellable>, |_result| {
58 });
59 webview.run_javascript("42", None::<&gio::Cancellable>, |result| {
60 match result {
61 Ok(result) => {
62 let context = result.global_context().unwrap();
63 let value = result.value().unwrap();
64 println!("is_boolean: {}", value.is_boolean(&context));
65 println!("is_number: {}", value.is_number(&context));
66 println!("{:?}", value.to_number(&context));
67 println!("{:?}", value.to_boolean(&context));
68 },
69 Err(error) => println!("{}", error),
70 }
71 });
72
73 window.connect_delete_event(|_, _| {
74 gtk::main_quit();
75 Inhibit(false)
76 });
77
78 gtk::main();
79}
Sourcepub fn value(&self) -> Option<ValueRef>
pub fn value(&self) -> Option<ValueRef>
Examples found in repository?
examples/main.rs (line 63)
34fn main() {
35 gtk::init().unwrap();
36
37 let window = Window::new(WindowType::Toplevel);
38 let context = WebContext::default().unwrap();
39 #[cfg(feature = "v2_4")]
40 context.set_web_extensions_initialization_user_data(&"webkit".to_variant());
41 context.set_web_extensions_directory("../webkit2gtk-webextension-rs/example/target/debug/");
42 #[cfg(feature = "v2_6")]
43 let webview = WebView::new_with_context_and_user_content_manager(&context, &UserContentManager::new());
44 #[cfg(not(feature = "v2_6"))]
45 let webview = WebView::with_context(&context);
46 webview.load_uri("https://crates.io/");
47 window.add(&webview);
48
49 let settings = WebViewExt::settings(&webview).unwrap();
50 settings.set_enable_developer_extras(true);
51
52 /*let inspector = webview.get_inspector().unwrap();
53 inspector.show();*/
54
55 window.show_all();
56
57 webview.run_javascript("alert('Hello');", None::<&gio::Cancellable>, |_result| {
58 });
59 webview.run_javascript("42", None::<&gio::Cancellable>, |result| {
60 match result {
61 Ok(result) => {
62 let context = result.global_context().unwrap();
63 let value = result.value().unwrap();
64 println!("is_boolean: {}", value.is_boolean(&context));
65 println!("is_number: {}", value.is_number(&context));
66 println!("{:?}", value.to_number(&context));
67 println!("{:?}", value.to_boolean(&context));
68 },
69 Err(error) => println!("{}", error),
70 }
71 });
72
73 window.connect_delete_event(|_, _| {
74 gtk::main_quit();
75 Inhibit(false)
76 });
77
78 gtk::main();
79}
Trait Implementations§
Source§impl Clone for JavascriptResult
impl Clone for JavascriptResult
Source§fn clone(&self) -> JavascriptResult
fn clone(&self) -> JavascriptResult
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for JavascriptResult
impl Debug for JavascriptResult
Source§impl Hash for JavascriptResult
impl Hash for JavascriptResult
Source§impl Ord for JavascriptResult
impl Ord for JavascriptResult
Source§fn cmp(&self, other: &JavascriptResult) -> Ordering
fn cmp(&self, other: &JavascriptResult) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl PartialEq for JavascriptResult
impl PartialEq for JavascriptResult
Source§impl PartialOrd for JavascriptResult
impl PartialOrd for JavascriptResult
Source§impl StaticType for JavascriptResult
impl StaticType for JavascriptResult
Source§fn static_type() -> Type
fn static_type() -> Type
Returns the type identifier of
Self
.impl Eq for JavascriptResult
impl StructuralPartialEq for JavascriptResult
Auto Trait Implementations§
impl Freeze for JavascriptResult
impl RefUnwindSafe for JavascriptResult
impl !Send for JavascriptResult
impl !Sync for JavascriptResult
impl Unpin for JavascriptResult
impl UnwindSafe for JavascriptResult
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more