OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/ui/zoom/zoom_controller.h" | 5 #include "chrome/browser/ui/zoom/zoom_controller.h" |
6 | 6 |
7 #include "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
8 #include "chrome/browser/chrome_notification_types.h" | 8 #include "chrome/browser/chrome_notification_types.h" |
9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/browser/ui/browser_finder.h" | 10 #include "chrome/browser/ui/browser_finder.h" |
11 #include "chrome/browser/ui/zoom/zoom_event_manager.h" | 11 #include "chrome/browser/ui/zoom/zoom_event_manager.h" |
12 #include "chrome/common/pref_names.h" | 12 #include "chrome/common/pref_names.h" |
13 #include "content/public/browser/host_zoom_map.h" | 13 #include "content/public/browser/host_zoom_map.h" |
14 #include "content/public/browser/navigation_entry.h" | 14 #include "content/public/browser/navigation_entry.h" |
15 #include "content/public/browser/notification_details.h" | 15 #include "content/public/browser/notification_details.h" |
16 #include "content/public/browser/notification_service.h" | 16 #include "content/public/browser/notification_service.h" |
17 #include "content/public/browser/notification_types.h" | 17 #include "content/public/browser/notification_types.h" |
18 #include "content/public/browser/render_process_host.h" | 18 #include "content/public/browser/render_process_host.h" |
19 #include "content/public/browser/render_view_host.h" | 19 #include "content/public/browser/render_view_host.h" |
20 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
21 #include "content/public/common/page_zoom.h" | 21 #include "content/public/common/page_zoom.h" |
22 #include "extensions/common/extension.h" | 22 #include "extensions/common/extension.h" |
23 #include "grit/theme_resources.h" | 23 #include "grit/theme_resources.h" |
24 #include "net/base/net_util.h" | 24 #include "net/base/net_util.h" |
25 | 25 |
26 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ZoomController); | 26 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ZoomController); |
27 | 27 |
28 ZoomController::ZoomController(content::WebContents* web_contents) | 28 ZoomController::ZoomController(content::WebContents* web_contents) |
29 : content::WebContentsObserver(web_contents), | 29 : content::WebContentsObserver(web_contents), |
| 30 can_show_bubble_(true), |
30 zoom_mode_(ZOOM_MODE_DEFAULT), | 31 zoom_mode_(ZOOM_MODE_DEFAULT), |
31 zoom_level_(1.0), | 32 zoom_level_(1.0), |
32 browser_context_(web_contents->GetBrowserContext()) { | 33 browser_context_(web_contents->GetBrowserContext()) { |
33 Profile* profile = | 34 Profile* profile = |
34 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 35 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
35 default_zoom_level_.Init( | 36 default_zoom_level_.Init( |
36 prefs::kDefaultZoomLevel, | 37 prefs::kDefaultZoomLevel, |
37 profile->GetPrefs(), | 38 profile->GetPrefs(), |
38 base::Bind( | 39 base::Bind( |
39 &ZoomController::UpdateState, base::Unretained(this), std::string())); | 40 &ZoomController::UpdateState, base::Unretained(this), std::string())); |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 // Use the navigation entry's URL instead of the WebContents' so virtual | 268 // Use the navigation entry's URL instead of the WebContents' so virtual |
268 // URLs work (e.g. chrome://settings). http://crbug.com/153950 | 269 // URLs work (e.g. chrome://settings). http://crbug.com/153950 |
269 content::NavigationEntry* entry = | 270 content::NavigationEntry* entry = |
270 web_contents()->GetController().GetLastCommittedEntry(); | 271 web_contents()->GetController().GetLastCommittedEntry(); |
271 if (!entry || | 272 if (!entry || |
272 host != net::GetHostOrSpecFromURL(entry->GetURL())) { | 273 host != net::GetHostOrSpecFromURL(entry->GetURL())) { |
273 return; | 274 return; |
274 } | 275 } |
275 } | 276 } |
276 | 277 |
277 // The zoom bubble can be shown for all zoom changes where the host is | 278 // The zoom bubble should not be shown for zoom changes where the host is |
278 // not empty. | 279 // empty. |
279 bool can_show_bubble = !host.empty(); | 280 bool can_show_bubble = can_show_bubble_ && !host.empty(); |
280 | 281 |
281 if (event_data_) { | 282 if (event_data_) { |
282 // For state changes initiated within the ZoomController, information about | 283 // For state changes initiated within the ZoomController, information about |
283 // the change should be sent. | 284 // the change should be sent. |
284 ZoomChangedEventData zoom_change_data = *event_data_; | 285 ZoomChangedEventData zoom_change_data = *event_data_; |
285 event_data_.reset(); | 286 event_data_.reset(); |
286 zoom_change_data.can_show_bubble = can_show_bubble; | 287 zoom_change_data.can_show_bubble = can_show_bubble; |
287 FOR_EACH_OBSERVER( | 288 FOR_EACH_OBSERVER( |
288 ZoomObserver, observers_, OnZoomChanged(zoom_change_data)); | 289 ZoomObserver, observers_, OnZoomChanged(zoom_change_data)); |
289 } else { | 290 } else { |
290 // TODO(wjmaclean) Should we consider having HostZoomMap send both old and | 291 // TODO(wjmaclean) Should we consider having HostZoomMap send both old and |
291 // new zoom levels here? | 292 // new zoom levels here? |
292 double zoom_level = GetZoomLevel(); | 293 double zoom_level = GetZoomLevel(); |
293 ZoomChangedEventData zoom_change_data( | 294 ZoomChangedEventData zoom_change_data( |
294 web_contents(), zoom_level, zoom_level, zoom_mode_, can_show_bubble); | 295 web_contents(), zoom_level, zoom_level, zoom_mode_, can_show_bubble); |
295 FOR_EACH_OBSERVER( | 296 FOR_EACH_OBSERVER( |
296 ZoomObserver, observers_, OnZoomChanged(zoom_change_data)); | 297 ZoomObserver, observers_, OnZoomChanged(zoom_change_data)); |
297 } | 298 } |
298 } | 299 } |
OLD | NEW |