OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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/browser_instant_controller.h" | 5 #include "chrome/browser/ui/browser_instant_controller.h" |
6 | 6 |
7 #include "chrome/browser/extensions/extension_service.h" | 7 #include "chrome/browser/extensions/extension_service.h" |
8 #include "chrome/browser/prefs/pref_service.h" | 8 #include "chrome/browser/prefs/pref_service.h" |
9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/browser/themes/theme_service.h" | 10 #include "chrome/browser/themes/theme_service.h" |
11 #include "chrome/browser/themes/theme_service_factory.h" | 11 #include "chrome/browser/themes/theme_service_factory.h" |
12 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
13 #include "chrome/browser/ui/browser_window.h" | 13 #include "chrome/browser/ui/browser_window.h" |
14 #include "chrome/browser/ui/omnibox/location_bar.h" | 14 #include "chrome/browser/ui/omnibox/location_bar.h" |
15 #include "chrome/browser/ui/omnibox/omnibox_view.h" | 15 #include "chrome/browser/ui/omnibox/omnibox_view.h" |
16 #include "chrome/browser/ui/search/search.h" | 16 #include "chrome/browser/ui/search/search.h" |
17 #include "chrome/browser/ui/search/search_tab_helper.h" | 17 #include "chrome/browser/ui/search/search_tab_helper.h" |
18 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 18 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
19 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 19 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
20 #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h" | 20 #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h" |
21 #include "chrome/common/chrome_notification_types.h" | 21 #include "chrome/common/chrome_notification_types.h" |
22 #include "chrome/common/pref_names.h" | 22 #include "chrome/common/pref_names.h" |
23 #include "content/public/browser/notification_service.h" | 23 #include "content/public/browser/notification_service.h" |
24 #include "grit/theme_resources.h" | 24 #include "grit/theme_resources.h" |
25 #include "ui/gfx/color_utils.h" | 25 #include "ui/gfx/color_utils.h" |
26 #include "ui/gfx/sys_color_change_listener.h" | 26 #include "ui/gfx/sys_color_change_listener.h" |
27 | 27 |
| 28 namespace { |
| 29 const char* GetInstantPrefName(Profile* profile) { |
| 30 return chrome::search::IsInstantExtendedAPIEnabled(profile) ? |
| 31 prefs::kInstantExtendedEnabled : prefs::kInstantEnabled; |
| 32 } |
| 33 } |
28 | 34 |
29 namespace chrome { | 35 namespace chrome { |
30 | 36 |
31 //////////////////////////////////////////////////////////////////////////////// | 37 //////////////////////////////////////////////////////////////////////////////// |
32 // BrowserInstantController, public: | 38 // BrowserInstantController, public: |
33 | 39 |
34 BrowserInstantController::BrowserInstantController(Browser* browser) | 40 BrowserInstantController::BrowserInstantController(Browser* browser) |
35 : browser_(browser), | 41 : browser_(browser), |
36 instant_(ALLOW_THIS_IN_INITIALIZER_LIST(this), | 42 instant_(ALLOW_THIS_IN_INITIALIZER_LIST(this), |
37 chrome::search::IsInstantExtendedAPIEnabled(browser->profile())), | 43 chrome::search::IsInstantExtendedAPIEnabled(browser->profile())), |
38 instant_unload_handler_(browser), | 44 instant_unload_handler_(browser), |
39 initialized_theme_info_(false), | 45 initialized_theme_info_(false), |
40 theme_area_height_(0) { | 46 theme_area_height_(0) { |
41 profile_pref_registrar_.Init(browser_->profile()->GetPrefs()); | 47 profile_pref_registrar_.Init(browser_->profile()->GetPrefs()); |
42 profile_pref_registrar_.Add( | 48 profile_pref_registrar_.Add( |
43 prefs::kInstantEnabled, | 49 GetInstantPrefName(browser_->profile()), |
44 base::Bind(&BrowserInstantController::ResetInstant, | 50 base::Bind(&BrowserInstantController::ResetInstant, |
45 base::Unretained(this))); | 51 base::Unretained(this))); |
46 ResetInstant(); | 52 ResetInstant(); |
47 browser_->search_model()->AddObserver(this); | 53 browser_->search_model()->AddObserver(this); |
48 | 54 |
49 #if defined(ENABLE_THEMES) | 55 #if defined(ENABLE_THEMES) |
50 // Listen for theme installation. | 56 // Listen for theme installation. |
51 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, | 57 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, |
52 content::Source<ThemeService>( | 58 content::Source<ThemeService>( |
53 ThemeServiceFactory::GetForProfile(browser_->profile()))); | 59 ThemeServiceFactory::GetForProfile(browser_->profile()))); |
54 #endif // defined(ENABLE_THEMES) | 60 #endif // defined(ENABLE_THEMES) |
55 } | 61 } |
56 | 62 |
57 BrowserInstantController::~BrowserInstantController() { | 63 BrowserInstantController::~BrowserInstantController() { |
58 browser_->search_model()->RemoveObserver(this); | 64 browser_->search_model()->RemoveObserver(this); |
59 } | 65 } |
60 | 66 |
61 bool BrowserInstantController::IsInstantEnabled(Profile* profile) { | 67 bool BrowserInstantController::IsInstantEnabled(Profile* profile) { |
62 return profile && !profile->IsOffTheRecord() && profile->GetPrefs() && | 68 return profile && !profile->IsOffTheRecord() && profile->GetPrefs() && |
63 profile->GetPrefs()->GetBoolean(prefs::kInstantEnabled); | 69 profile->GetPrefs()->GetBoolean(GetInstantPrefName(profile)); |
64 } | 70 } |
65 | 71 |
66 void BrowserInstantController::RegisterUserPrefs(PrefService* prefs) { | 72 void BrowserInstantController::RegisterUserPrefs(PrefService* prefs) { |
67 prefs->RegisterBooleanPref(prefs::kInstantConfirmDialogShown, false, | 73 prefs->RegisterBooleanPref(prefs::kInstantConfirmDialogShown, false, |
68 PrefService::SYNCABLE_PREF); | 74 PrefService::SYNCABLE_PREF); |
| 75 prefs->RegisterBooleanPref(prefs::kInstantExtendedEnabled, true, |
| 76 PrefService::SYNCABLE_PREF); |
69 prefs->RegisterBooleanPref(prefs::kInstantEnabled, false, | 77 prefs->RegisterBooleanPref(prefs::kInstantEnabled, false, |
70 PrefService::SYNCABLE_PREF); | 78 PrefService::SYNCABLE_PREF); |
71 } | 79 } |
72 | 80 |
73 bool BrowserInstantController::OpenInstant(WindowOpenDisposition disposition) { | 81 bool BrowserInstantController::OpenInstant(WindowOpenDisposition disposition) { |
74 // Unsupported dispositions. | 82 // Unsupported dispositions. |
75 if (disposition == NEW_BACKGROUND_TAB || disposition == NEW_WINDOW) | 83 if (disposition == NEW_BACKGROUND_TAB || disposition == NEW_WINDOW) |
76 return false; | 84 return false; |
77 | 85 |
78 // The omnibox currently doesn't use other dispositions, so we don't attempt | 86 // The omnibox currently doesn't use other dispositions, so we don't attempt |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 // part of the image overlay should draw, 'cos the origin is top-left. | 278 // part of the image overlay should draw, 'cos the origin is top-left. |
271 if (!browser_->search_model()->mode().is_ntp() || | 279 if (!browser_->search_model()->mode().is_ntp() || |
272 theme_info_.theme_id.empty() || | 280 theme_info_.theme_id.empty() || |
273 theme_info_.image_vertical_alignment == THEME_BKGRND_IMAGE_ALIGN_TOP) { | 281 theme_info_.image_vertical_alignment == THEME_BKGRND_IMAGE_ALIGN_TOP) { |
274 return; | 282 return; |
275 } | 283 } |
276 instant_.ThemeAreaHeightChanged(theme_area_height_); | 284 instant_.ThemeAreaHeightChanged(theme_area_height_); |
277 } | 285 } |
278 | 286 |
279 } // namespace chrome | 287 } // namespace chrome |
OLD | NEW |