-
-
Notifications
You must be signed in to change notification settings - Fork 375
feat: add WebView::set_cookie and WebView::delete_cookie
#1569
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e49170d
feat: add `WebView::set_cookie` and `WebView::delete_cookie`
WSH032 bcfdb90
feat: implement for `wkwebview`
WSH032 4d235fc
chore: changes-files
WSH032 ddbfe58
feat: implement SameSite cookie policy for wkwebview
WSH032 45a89fb
refactor: use `&` instead of `&*`
WSH032 c353310
refactor: remove `debug_assert` for `HttpOnly`
WSH032 ac95e3f
docs: add `delete_cookie` in example
WSH032 7cd795b
chore: remove redundant samesite setting
pewsheen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "wry": "patch" | ||
| --- | ||
|
|
||
| Add `WebView::set_cookie` and `WebView::delete_cookie` APIs. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| // Copyright 2020-2023 Tauri Programme within The Commons Conservancy | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| use tao::{ | ||
| event::{Event, WindowEvent}, | ||
| event_loop::{ControlFlow, EventLoop}, | ||
| window::WindowBuilder, | ||
| }; | ||
| use wry::WebViewBuilder; | ||
|
|
||
| fn main() -> wry::Result<()> { | ||
| let event_loop = EventLoop::new(); | ||
| let window = WindowBuilder::new().build(&event_loop).unwrap(); | ||
|
|
||
| let builder = WebViewBuilder::new().with_url("https://www.httpbin.org/cookies/set?foo=bar"); | ||
|
|
||
| #[cfg(any( | ||
| target_os = "windows", | ||
| target_os = "macos", | ||
| target_os = "ios", | ||
| target_os = "android" | ||
| ))] | ||
| let webview = builder.build(&window)?; | ||
| #[cfg(not(any( | ||
| target_os = "windows", | ||
| target_os = "macos", | ||
| target_os = "ios", | ||
| target_os = "android" | ||
| )))] | ||
| let webview = { | ||
| use tao::platform::unix::WindowExtUnix; | ||
| use wry::WebViewBuilderExtUnix; | ||
| let vbox = window.default_vbox().unwrap(); | ||
| builder.build_gtk(vbox)? | ||
| }; | ||
|
|
||
| webview.set_cookie( | ||
| cookie::Cookie::build(("foo1", "bar1")) | ||
| .domain("www.httpbin.org") | ||
| .path("/") | ||
| .secure(true) | ||
| .http_only(true) | ||
| .max_age(cookie::time::Duration::seconds(10)) | ||
| .inner(), | ||
| )?; | ||
|
|
||
| let cookie_deleted = cookie::Cookie::build(("will_be_deleted", "will_be_deleted")); | ||
|
|
||
| webview.set_cookie(cookie_deleted.inner())?; | ||
| println!("Setting Cookies:"); | ||
| for cookie in webview.cookies()? { | ||
| println!("\t{cookie}"); | ||
| } | ||
|
|
||
| println!("After Deleting:"); | ||
| webview.delete_cookie(cookie_deleted.inner())?; | ||
| for cookie in webview.cookies()? { | ||
| println!("\t{cookie}"); | ||
| } | ||
|
|
||
| event_loop.run(move |event, _, control_flow| { | ||
| *control_flow = ControlFlow::Wait; | ||
|
|
||
| if let Event::WindowEvent { | ||
| event: WindowEvent::CloseRequested, | ||
| .. | ||
| } = event | ||
| { | ||
| *control_flow = ControlFlow::Exit; | ||
| } | ||
| }); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.