Auto merge of #15794 - paulrouget:head_parsed_url, r=asajeffrey

Notify embedder when history changes

`WindowMethods::set_page_url` is only called when the embedder set the URL. It is not called when the page url is updated. I believe that instead we should just pass the URL to `head_parsed`.

---
<!-- 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 #15439 #15643 and #15642 (github issue number if applicable).

<!-- Either: -->
- [ ] There are tests for these changes OR
- [x] These changes do not require tests because I'm not sure how to test that

<!-- 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/15794)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2017-04-25 14:14:31 -05:00 committed by GitHub
commit dc594face8
6 changed files with 111 additions and 77 deletions

View file

@ -26,7 +26,7 @@ use euclid::size::{Size2D, TypedSize2D};
use gleam::gl;
use msg::constellation_msg::{Key, KeyModifiers};
use net_traits::net_error_list::NetError;
use script_traits::DevicePixel;
use script_traits::{DevicePixel, LoadData};
use servo_geometry::DeviceIndependentPixel;
use std::cell::RefCell;
use std::ffi::CString;
@ -350,15 +350,15 @@ impl WindowMethods for Window {
}
}
fn load_start(&self, back: bool, forward: bool) {
fn load_start(&self) {
let browser = self.cef_browser.borrow();
let browser = match *browser {
None => return,
Some(ref browser) => browser,
};
let back = browser.downcast().back.get();
let forward = browser.downcast().forward.get();
browser.downcast().loading.set(true);
browser.downcast().back.set(back);
browser.downcast().forward.set(forward);
browser.downcast().favicons.borrow_mut().clear();
if check_ptr_exist!(browser.get_host().get_client(), get_load_handler) &&
check_ptr_exist!(browser.get_host().get_client().get_load_handler(), on_loading_state_change) {
@ -369,16 +369,16 @@ impl WindowMethods for Window {
}
}
fn load_end(&self, back: bool, forward: bool, _: bool) {
fn load_end(&self) {
// FIXME(pcwalton): The status code 200 is a lie.
let browser = self.cef_browser.borrow();
let browser = match *browser {
None => return,
Some(ref browser) => browser,
};
let back = browser.downcast().back.get();
let forward = browser.downcast().forward.get();
browser.downcast().loading.set(false);
browser.downcast().back.set(back);
browser.downcast().forward.set(forward);
if check_ptr_exist!(browser.get_host().get_client(), get_load_handler) &&
check_ptr_exist!(browser.get_host().get_client().get_load_handler(), on_loading_state_change) {
browser.get_host()
@ -448,20 +448,21 @@ impl WindowMethods for Window {
}
}
fn set_page_url(&self, url: ServoUrl) {
// it seems to be the case that load start is always called
// IMMEDIATELY before address change, so just stick it here
on_load_start(self);
fn history_changed(&self, history: Vec<LoadData>, current: usize) {
let browser = self.cef_browser.borrow();
let browser = match *browser {
None => return,
Some(ref browser) => browser,
};
let can_go_back = current > 0;
let can_go_forward = current < history.len() - 1;
browser.downcast().back.set(can_go_back);
browser.downcast().forward.set(can_go_forward);
let frame = browser.get_main_frame();
let servoframe = frame.downcast();
// FIXME(https://github.com/rust-lang/rust/issues/23338)
let mut frame_url = servoframe.url.borrow_mut();
*frame_url = url.into_string();
let mut frame_url = frame.downcast().url.borrow_mut();
*frame_url = history[current].url.to_string();
let utf16_chars: Vec<u16> = frame_url.encode_utf16().collect();
if check_ptr_exist!(browser.get_host().get_client(), get_display_handler) &&
check_ptr_exist!(browser.get_host().get_client().get_display_handler(), on_address_change) {
@ -516,21 +517,6 @@ impl CompositorProxy for CefCompositorProxy {
}
}
fn on_load_start(window: &Window) {
let browser = window.cef_browser.borrow();
let browser = match *browser {
None => return,
Some(ref browser) => browser,
};
if check_ptr_exist!(browser.get_host().get_client(), get_load_handler) &&
check_ptr_exist!(browser.get_host().get_client().get_load_handler(), on_load_start) {
browser.get_host()
.get_client()
.get_load_handler()
.on_load_start((*browser).clone(), browser.get_main_frame());
}
}
#[cfg(target_os="macos")]
pub fn app_wakeup() {
use cocoa::appkit::{NSApp, NSApplication, NSApplicationDefined};

View file

@ -27,7 +27,7 @@ use msg::constellation_msg::{ALT, CONTROL, KeyState, NONE, SHIFT, SUPER};
use net_traits::net_error_list::NetError;
#[cfg(any(target_os = "linux", target_os = "macos"))]
use osmesa_sys;
use script_traits::{DevicePixel, TouchEventType, TouchpadPressurePhase};
use script_traits::{DevicePixel, LoadData, TouchEventType, TouchpadPressurePhase};
use servo_config::opts;
use servo_config::prefs::PREFS;
use servo_config::resource_files;
@ -1099,18 +1099,14 @@ impl WindowMethods for Window {
}
}
fn set_page_url(&self, url: ServoUrl) {
*self.current_url.borrow_mut() = Some(url);
}
fn status(&self, _: Option<String>) {
}
fn load_start(&self, _: bool, _: bool) {
fn load_start(&self) {
}
fn load_end(&self, _: bool, _: bool, root: bool) {
if root && opts::get().no_native_titlebar {
fn load_end(&self) {
if opts::get().no_native_titlebar {
match self.kind {
WindowKind::Window(ref window) => {
window.show();
@ -1120,6 +1116,10 @@ impl WindowMethods for Window {
}
}
fn history_changed(&self, history: Vec<LoadData>, current: usize) {
*self.current_url.borrow_mut() = Some(history[current].url.clone());
}
fn load_error(&self, _: NetError, _: String) {
}