Skip to content
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

Clipboard refactoring #23564

Merged
merged 14 commits into from Jul 3, 2019
Merged

Clipboard refactoring #23564

merged 14 commits into from Jul 3, 2019

Conversation

@mmiecz
Copy link
Contributor

mmiecz commented Jun 13, 2019

This PR removes clipboard handling from the constellation. Instead, now embedder handles it.


  • ./mach build -d does not report any errors
  • ./mach test-tidy does not report any errors
  • These changes fix #23440 (GitHub issue number if applicable)
  • There are tests for these changes OR
  • These changes do not require tests because it is enough to test manually in input box, if copying and pasting still works .

This change is Reviewable

@highfive
Copy link

highfive commented Jun 13, 2019

Thanks for the pull request, and welcome! The Servo team is excited to review your changes, and you should hear from @emilio (or someone else) soon.

@highfive
Copy link

highfive commented Jun 13, 2019

Heads up! This PR modifies the following files:

  • @asajeffrey: components/script/clipboard_provider.rs, components/constellation/constellation.rs
  • @cbrewster: components/constellation/constellation.rs
  • @paulrouget: ports/glutin/browser.rs, ports/glutin/main2.rs, ports/glutin/Cargo.toml, components/constellation/constellation.rs
  • @KiChjang: components/script/clipboard_provider.rs, components/script_traits/script_msg.rs
@highfive
Copy link

highfive commented Jun 13, 2019

warning Warning warning

  • These commits modify script code, but no tests are modified. Please consider adding a test!
@jdm
Copy link
Member

jdm commented Jun 13, 2019

error: unused extern crate
 --> ports/glutin/main2.rs:5:1
  |
5 | extern crate clipboard;
  | ^^^^^^^^^^^^^^^^^^^^^^^ help: remove it
  |
  = note: `-D unused-extern-crates` implied by `-D warnings`
Copy link
Member

jdm left a comment

Looks good!

components/script/clipboard_provider.rs Show resolved Hide resolved
@@ -2,14 +2,14 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

extern crate clipboard;

This comment has been minimized.

@jdm

jdm Jun 13, 2019

Member

Let's remove this.

This comment has been minimized.

@mmiecz

mmiecz Jun 15, 2019

Author Contributor

Done, removed.

@jdm
Copy link
Member

jdm commented Jun 13, 2019

If you build ./mach build --libsimpleservo, you should find some other places where you need to handle the new messages.

@jdm jdm assigned jdm and unassigned emilio Jun 13, 2019
Copy link
Member

jdm left a comment

Sorry for the delay; last week was very busy. One last change which will allow us to provide different clipboard solutions on other platforms like android/magic leap/hololens!

@@ -7,6 +7,7 @@ edition = "2018"
publish = false

[dependencies]
clipboard = "0.5"

This comment has been minimized.

@jdm

jdm Jun 24, 2019

Member

Since libsimpleservo/api is a platform-agnostic embedding API, we should not add a platform-specific dependency like clipboard to it.

@@ -516,6 +526,28 @@ impl ServoGlue {
}
self.events.push(WindowEvent::SelectBrowser(new_browser_id));
},
EmbedderMsg::GetClipboardContents(sender) => {
let contents = match self.clipboard_ctx {

This comment has been minimized.

@jdm

jdm Jun 24, 2019

Member

Instead of directly manipulating the clipboard for the GetClipboardContents and SetClipboardContents messages, let's add new callbacks to HostTrait (get_clipboard_contents() can return an Option and set_clipboard_contents can accept a String) and call those instead. See how EmbedderMsg::HistoryChanged is handled earlier.

…and call them instead of directly handlind clipboard
@mmiecz
Copy link
Contributor Author

mmiecz commented Jun 24, 2019

Ok thanks for the tips @jdm :). I've removed direct handling of clipboard from libsimpleservo, and added methods to HostTrait as mentioned.

I am not sure if I'm doing implementation right though?:

 fn get_clipboard_contents(&self) -> Option<String> {
        debug!("get_clipboard_contents");
        let raw_contents = (self.0.get_clipboard_contents)();
        if raw_contents.is_null() {
            return None;
        }
        let c_str = unsafe { CStr::from_ptr(raw_contents) };
        let contents_str = c_str.to_str().expect("Can't create str");
        Some(contents_str.to_owned())
    }

    fn set_clipboard_contents(&self, contents: String) {
        debug!("set_clipboard_contents");
        let contents = CString::new(contents).expect("Can't create string");
        let contents_ptr = contents.as_ptr();
        mem::forget(contents);
        (self.0.set_clipboard_contents)(contents_ptr);
    }

I guess this two methods should call some external ( platform specific ) function for getting and setting system clipboard. This is just for capi, but this should be done for jniapi also, right? Call java get/setClipboardContents from jniapi/lib/src.rs?

@jdm
Copy link
Member

jdm commented Jun 24, 2019

For jniapi and mlservo you can leave stub implementations, unless you are familiar enough with android that you're confident about the JNI work :)

@jdm
Copy link
Member

jdm commented Jul 3, 2019

@bors-servo
Copy link
Contributor

bors-servo commented Jul 3, 2019

📌 Commit 775ff3b has been approved by jdm

@bors-servo
Copy link
Contributor

bors-servo commented Jul 3, 2019

Testing commit 775ff3b with merge 1601e75...

bors-servo added a commit that referenced this pull request Jul 3, 2019
Clipboard refactoring

<!-- Please describe your changes on the following line: -->
This PR removes clipboard handling from the constellation. Instead, now embedder handles it.

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #23440 (GitHub issue number if applicable)

<!-- Either: -->
- [ ] There are tests for these changes OR
- [X] These changes do not require tests because it is enough to test manually in input box, if copying and pasting still works .

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/23564)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Jul 3, 2019

💔 Test failed - status-taskcluster

@jdm
Copy link
Member

jdm commented Jul 3, 2019

More warnings from other platforms:

�[0m�[1m�[38;5;9merror�[0m�[0m�[1m: unused variable: `contents`�[0m
�[0m   �[0m�[0m�[1m�[38;5;12m--> �[0m�[0mports/libsimpleservo/jniapi/src/lib.rs:484:38�[0m
�[0m    �[0m�[0m�[1m�[38;5;12m|�[0m
�[0m�[1m�[38;5;12m484�[0m�[0m �[0m�[0m�[1m�[38;5;12m| �[0m�[0m    fn set_clipboard_contents(&self, contents: String) {}�[0m
�[0m    �[0m�[0m�[1m�[38;5;12m| �[0m�[0m                                     �[0m�[0m�[1m�[38;5;9m^^^^^^^^�[0m�[0m �[0m�[0m�[1m�[38;5;9mhelp: consider prefixing with an underscore: `_contents`�[0m
�[0m    �[0m�[0m�[1m�[38;5;12m|�[0m
�[0m    �[0m�[0m�[1m�[38;5;12m= �[0m�[0m�[1mnote�[0m�[0m: `-D unused-variables` implied by `-D warnings`�[0m
error: unused variable: `contents`
   --> ports/libmlservo/src/lib.rs:386:38
    |
386 |     fn set_clipboard_contents(&self, contents: String) {}
    |                                      ^^^^^^^^ help: consider prefixing with an underscore: `_contents`
    |
    = note: `-D unused-variables` implied by `-D warnings`
@mmiecz
Copy link
Contributor Author

mmiecz commented Jul 3, 2019

Can I build/test other platforms somehow on my Linux machine to see and fix such failures before issuing a PR? :)

@jdm
Copy link
Member

jdm commented Jul 3, 2019

The jni one you could build by following https://github.com/servo/servo/wiki/Building-for-Android, but it's not necessarily worth it. You can see all of the failures from the previous build by looking at https://treeherder.allizom.org/#/jobs?repo=servo-auto .

@jdm
Copy link
Member

jdm commented Jul 3, 2019

The libmlservo can only be built by people with access to the Magic Leap SDK, which is restricted to a small set of developers right now.

@mmiecz
Copy link
Contributor Author

mmiecz commented Jul 3, 2019

Thanks @jdm for explanation. I've fixed the unused arguments warnings.

@jdm
Copy link
Member

jdm commented Jul 3, 2019

@bors-servo r+
Thanks!

@bors-servo
Copy link
Contributor

bors-servo commented Jul 3, 2019

📌 Commit 7fb2bbe has been approved by jdm

@bors-servo
Copy link
Contributor

bors-servo commented Jul 3, 2019

Testing commit 7fb2bbe with merge e382266...

bors-servo added a commit that referenced this pull request Jul 3, 2019
Clipboard refactoring

<!-- Please describe your changes on the following line: -->
This PR removes clipboard handling from the constellation. Instead, now embedder handles it.

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #23440 (GitHub issue number if applicable)

<!-- Either: -->
- [ ] There are tests for these changes OR
- [X] These changes do not require tests because it is enough to test manually in input box, if copying and pasting still works .

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/23564)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Jul 3, 2019

☀️ Test successful - linux-rel-css, linux-rel-wpt, status-taskcluster
Approved by: jdm
Pushing e382266 to master...

@bors-servo bors-servo merged commit 7fb2bbe into servo:master Jul 3, 2019
3 checks passed
3 checks passed
Taskcluster (pull_request) TaskGroup: success
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
homu Test successful
Details
@mmiecz mmiecz deleted the mmiecz:clipboard-refactoring branch Jul 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

5 participants
You can’t perform that action at this time.