diff --git a/components/compositing/lib.rs b/components/compositing/lib.rs index 3a7634e3f57..dbb835e8bbe 100644 --- a/components/compositing/lib.rs +++ b/components/compositing/lib.rs @@ -71,6 +71,8 @@ pub enum ConstellationMsg { AllowNavigationResponse(PipelineId, bool), /// Request to load a page. LoadUrl(TopLevelBrowsingContextId, ServoUrl), + /// Clear the network cache. + ClearCache, /// Request to traverse the joint session history of the provided browsing context. TraverseHistory(TopLevelBrowsingContextId, TraversalDirection), /// Inform the constellation of a window being resized. @@ -143,6 +145,7 @@ impl fmt::Debug for ConstellationMsg { MediaSessionAction(..) => "MediaSessionAction", ChangeBrowserVisibility(..) => "ChangeBrowserVisibility", IMEDismissed => "IMEDismissed", + ClearCache => "ClearCache", }; write!(formatter, "ConstellationMsg::{}", variant) } diff --git a/components/compositing/windowing.rs b/components/compositing/windowing.rs index c308bf196f6..571ff7181a8 100644 --- a/components/compositing/windowing.rs +++ b/components/compositing/windowing.rs @@ -95,6 +95,8 @@ pub enum WindowEvent { ToggleWebRenderDebug(WebRenderDebugOption), /// Capture current WebRender CaptureWebRender, + /// Clear the network cache. + ClearCache, /// Toggle sampling profiler with the given sampling rate and max duration. ToggleSamplingProfiler(Duration, Duration), /// Sent when the user triggers a media action through the UA exposed media UI @@ -137,6 +139,7 @@ impl Debug for WindowEvent { WindowEvent::MediaSessionAction(..) => write!(f, "MediaSessionAction"), WindowEvent::ChangeBrowserVisibility(..) => write!(f, "ChangeBrowserVisibility"), WindowEvent::IMEDismissed => write!(f, "IMEDismissed"), + WindowEvent::ClearCache => write!(f, "ClearCache"), } } } diff --git a/components/constellation/constellation.rs b/components/constellation/constellation.rs index 4d94533ffae..4b06efd0cdf 100644 --- a/components/constellation/constellation.rs +++ b/components/constellation/constellation.rs @@ -1529,6 +1529,10 @@ where }, }; }, + FromCompositorMsg::ClearCache => { + self.public_resource_threads.clear_cache(); + self.private_resource_threads.clear_cache(); + }, // Load a new page from a typed url // If there is already a pending page (self.pending_changes), it will not be overridden; // However, if the id is not encompassed by another change, it will be. diff --git a/components/net/http_cache.rs b/components/net/http_cache.rs index 592ad7a99aa..81109df2bda 100644 --- a/components/net/http_cache.rs +++ b/components/net/http_cache.rs @@ -902,4 +902,9 @@ impl HttpCache { // See A cache MAY complete a stored incomplete response by making a subsequent range request // https://tools.ietf.org/html/rfc7234#section-3.1 } + + /// Clear the contents of this cache. + pub fn clear(&mut self) { + self.entries.clear(); + } } diff --git a/components/net/resource_thread.rs b/components/net/resource_thread.rs index 07c77c705f9..a1d6c849098 100644 --- a/components/net/resource_thread.rs +++ b/components/net/resource_thread.rs @@ -354,6 +354,9 @@ impl ResourceChannelManager { CoreResourceMsg::Synchronize(sender) => { let _ = sender.send(()); }, + CoreResourceMsg::ClearCache => { + http_state.http_cache.write().unwrap().clear(); + }, CoreResourceMsg::ToFileManager(msg) => self.resource_manager.filemanager.handle(msg), CoreResourceMsg::Exit(sender) => { if let Some(ref config_dir) = self.config_dir { diff --git a/components/net_traits/lib.rs b/components/net_traits/lib.rs index 83d9513d987..de7871e8348 100644 --- a/components/net_traits/lib.rs +++ b/components/net_traits/lib.rs @@ -361,6 +361,10 @@ impl ResourceThreads { storage_thread: s, } } + + pub fn clear_cache(&self) { + let _ = self.core_thread.send(CoreResourceMsg::ClearCache); + } } impl IpcSend for ResourceThreads { @@ -459,6 +463,8 @@ pub enum CoreResourceMsg { RemoveHistoryStates(Vec), /// Synchronization message solely for knowing the state of the ResourceChannelManager loop Synchronize(IpcSender<()>), + /// Clear the network cache. + ClearCache, /// Send the service worker network mediator for an origin to CoreResourceThread NetworkMediator(IpcSender, ImmutableOrigin), /// Message forwarded to file manager's handler diff --git a/components/servo/lib.rs b/components/servo/lib.rs index 0944d12547e..2bcc5694074 100644 --- a/components/servo/lib.rs +++ b/components/servo/lib.rs @@ -583,6 +583,13 @@ where } }, + WindowEvent::ClearCache => { + let msg = ConstellationMsg::ClearCache; + if let Err(e) = self.constellation_chan.send(msg) { + warn!("Sending clear cache to constellation failed ({:?}).", e); + } + }, + WindowEvent::MouseWindowEventClass(mouse_window_event) => { self.compositor .on_mouse_window_event_class(mouse_window_event); diff --git a/ports/libsimpleservo/api/src/lib.rs b/ports/libsimpleservo/api/src/lib.rs index a05df67317f..f3fd0078108 100644 --- a/ports/libsimpleservo/api/src/lib.rs +++ b/ports/libsimpleservo/api/src/lib.rs @@ -355,6 +355,13 @@ impl ServoGlue { }) } + /// Reload the page. + pub fn clear_cache(&mut self) -> Result<(), &'static str> { + info!("clear_cache"); + let event = WindowEvent::ClearCache; + self.process_event(event) + } + /// Reload the page. pub fn reload(&mut self) -> Result<(), &'static str> { info!("reload"); diff --git a/ports/libsimpleservo/capi/src/lib.rs b/ports/libsimpleservo/capi/src/lib.rs index 9bace40a29d..700e03b9a3c 100644 --- a/ports/libsimpleservo/capi/src/lib.rs +++ b/ports/libsimpleservo/capi/src/lib.rs @@ -565,6 +565,14 @@ pub extern "C" fn load_uri(url: *const c_char) -> bool { }) } +#[no_mangle] +pub extern "C" fn clear_cache() { + catch_any_panic(|| { + debug!("clear_cache"); + call(|s| s.clear_cache()) + }); +} + #[no_mangle] pub extern "C" fn reload() { catch_any_panic(|| { diff --git a/support/hololens/ServoApp/ServoControl/Servo.h b/support/hololens/ServoApp/ServoControl/Servo.h index 8fc01b73fe1..db2ade2e14e 100644 --- a/support/hololens/ServoApp/ServoControl/Servo.h +++ b/support/hololens/ServoApp/ServoControl/Servo.h @@ -67,7 +67,10 @@ public: void KeyDown(const char *k) { key_down(k); } void KeyUp(const char *k) { key_up(k); } - void Reload() { reload(); } + void Reload() { + clear_cache(); + reload(); + } void Stop() { stop(); } bool LoadUri(hstring uri) { return load_uri(*hstring2char(uri)); } void ChangeVisibility(bool visible) { change_visibility(visible); }