OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/host_zoom_map_observer.h" | 5 #include "content/browser/host_zoom_map_observer.h" |
6 | 6 |
7 #include "content/browser/frame_host/render_frame_host_impl.h" | 7 #include "content/browser/frame_host/render_frame_host_impl.h" |
8 #include "content/browser/host_zoom_map_impl.h" | 8 #include "content/browser/host_zoom_map_impl.h" |
9 #include "content/public/browser/navigation_handle.h" | 9 #include "content/public/browser/navigation_handle.h" |
10 #include "content/public/browser/render_view_host.h" | 10 #include "content/public/browser/render_view_host.h" |
11 #include "content/public/browser/storage_partition.h" | 11 #include "content/public/browser/storage_partition.h" |
12 #include "content/public/common/associated_interface_provider.h" | 12 #include "content/public/common/associated_interface_provider.h" |
13 | 13 |
14 namespace content { | 14 namespace content { |
15 | 15 |
16 HostZoomMapObserver::HostZoomMapObserver(WebContents* web_contents) | 16 HostZoomMapObserver::HostZoomMapObserver(WebContents* web_contents) |
17 : WebContentsObserver(web_contents) {} | 17 : WebContentsObserver(web_contents) {} |
18 | 18 |
19 HostZoomMapObserver::~HostZoomMapObserver() {} | 19 HostZoomMapObserver::~HostZoomMapObserver() {} |
20 | 20 |
21 void HostZoomMapObserver::ReadyToCommitNavigation( | 21 void HostZoomMapObserver::ReadyToCommitNavigation( |
22 NavigationHandle* navigation_handle) { | 22 NavigationHandle* navigation_handle) { |
23 if (!navigation_handle->IsInMainFrame()) | 23 if (!navigation_handle->IsInMainFrame()) |
24 return; | 24 return; |
25 | 25 |
26 DCHECK(host_zoom_.is_bound()); | |
27 if (!host_zoom_.is_bound()) | |
28 return; | |
29 | |
30 RenderFrameHost* render_frame_host = | 26 RenderFrameHost* render_frame_host = |
31 navigation_handle->GetRenderFrameHost(); | 27 navigation_handle->GetRenderFrameHost(); |
28 const auto& entry = host_zoom_ptrs_.find(render_frame_host); | |
29 if (entry == host_zoom_ptrs_.end()) | |
30 return; | |
31 | |
32 const mojom::HostZoomAssociatedPtr& host_zoom = entry->second; | |
33 DCHECK(host_zoom.is_bound()); | |
34 DCHECK(!host_zoom.encountered_error()); | |
35 | |
32 RenderProcessHost* render_process_host = render_frame_host->GetProcess(); | 36 RenderProcessHost* render_process_host = render_frame_host->GetProcess(); |
33 HostZoomMapImpl* host_zoom_map = static_cast<HostZoomMapImpl*>( | 37 HostZoomMapImpl* host_zoom_map = static_cast<HostZoomMapImpl*>( |
34 render_process_host->GetStoragePartition()->GetHostZoomMap()); | 38 render_process_host->GetStoragePartition()->GetHostZoomMap()); |
35 double zoom_level = host_zoom_map->GetZoomLevelForView( | 39 double zoom_level = host_zoom_map->GetZoomLevelForView( |
36 navigation_handle->GetURL(), render_process_host->GetID(), | 40 navigation_handle->GetURL(), render_process_host->GetID(), |
37 render_frame_host->GetRenderViewHost()->GetRoutingID()); | 41 render_frame_host->GetRenderViewHost()->GetRoutingID()); |
38 host_zoom_->SetHostZoomLevel(navigation_handle->GetURL(), zoom_level); | 42 host_zoom->SetHostZoomLevel(navigation_handle->GetURL(), zoom_level); |
39 } | 43 } |
40 | 44 |
41 void HostZoomMapObserver::RenderFrameCreated(RenderFrameHost* rfh) { | 45 void HostZoomMapObserver::RenderFrameCreated(RenderFrameHost* rfh) { |
42 rfh->GetRemoteAssociatedInterfaces()->GetInterface(&host_zoom_); | 46 mojom::HostZoomAssociatedPtr host_zoom; |
47 rfh->GetRemoteAssociatedInterfaces()->GetInterface(&host_zoom); | |
48 host_zoom.set_connection_error_handler( | |
49 base::Bind(&HostZoomMapObserver::OnConnectionError, | |
50 base::Unretained(this), base::Unretained(rfh))); | |
51 host_zoom_ptrs_[rfh] = std::move(host_zoom); | |
52 } | |
53 | |
54 void HostZoomMapObserver::OnConnectionError(RenderFrameHost* rfh) { | |
55 // NOTE: It is not safe to do anything with |rfh| other than use it as a | |
56 // key here. | |
wjmaclean
2016/12/16 14:45:35
Presumably this is on account of a rfh being delet
ncarter (slow)
2016/12/16 18:21:12
The scenario wjmaclean describes seems plausible.
blundell
2016/12/19 17:03:14
Changed. For my own curiosity: the case where this
ncarter (slow)
2016/12/19 19:21:16
I would hope we don't do ReadyToCommitNavigation o
| |
57 const auto& entry = host_zoom_ptrs_.find(rfh); | |
58 DCHECK(entry != host_zoom_ptrs_.end()); | |
59 host_zoom_ptrs_.erase(entry); | |
43 } | 60 } |
44 | 61 |
45 } // namespace content | 62 } // namespace content |
OLD | NEW |