Chromium Code Reviews| 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 #include "base/compiler_specific.h" | 6 #include "base/compiler_specific.h" |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/browser/prefs/session_startup_pref.h" | 10 #include "chrome/browser/prefs/session_startup_pref.h" |
| 11 #include "chrome/browser/protector/base_prefs_change.h" | 11 #include "chrome/browser/protector/base_prefs_change.h" |
| 12 #include "chrome/browser/protector/histograms.h" | 12 #include "chrome/browser/protector/histograms.h" |
| 13 #include "chrome/browser/protector/protector_service.h" | 13 #include "chrome/browser/protector/protector_service.h" |
| 14 #include "chrome/browser/protector/protector_service_factory.h" | 14 #include "chrome/browser/protector/protector_service_factory.h" |
| 15 #include "chrome/browser/tabs/tab_strip_model.h" | 15 #include "chrome/browser/tabs/tab_strip_model.h" |
| 16 #include "chrome/browser/ui/browser.h" | 16 #include "chrome/browser/ui/browser.h" |
| 17 #include "chrome/browser/ui/browser_navigator.h" | 17 #include "chrome/browser/ui/browser_navigator.h" |
| 18 #include "chrome/common/pref_names.h" | 18 #include "chrome/common/pref_names.h" |
| 19 #include "grit/chromium_strings.h" | 19 #include "grit/chromium_strings.h" |
| 20 #include "grit/generated_resources.h" | 20 #include "grit/generated_resources.h" |
| 21 #include "grit/theme_resources.h" | 21 #include "grit/theme_resources.h" |
| 22 #include "ui/base/l10n/l10n_util.h" | 22 #include "ui/base/l10n/l10n_util.h" |
| 23 | 23 |
| 24 namespace protector { | 24 namespace protector { |
| 25 | 25 |
| 26 namespace { | |
| 27 | |
| 28 // Priority for the display name. | |
| 29 const size_t kNamePriority = 50U; | |
|
whywhat
2012/04/06 16:28:32
Maybe we should put the priorities in a single fil
Ivan Korotkov
2012/04/09 14:46:47
Done.
| |
| 30 | |
| 31 } // namespace | |
| 32 | |
| 26 // Session startup settings change tracked by Protector. | 33 // Session startup settings change tracked by Protector. |
| 27 class SessionStartupChange : public BasePrefsChange { | 34 class SessionStartupChange : public BasePrefsChange { |
| 28 public: | 35 public: |
| 29 SessionStartupChange(const SessionStartupPref& actual_startup_pref, | 36 SessionStartupChange(const SessionStartupPref& actual_startup_pref, |
| 30 const PinnedTabCodec::Tabs& actual_pinned_tabs, | 37 const PinnedTabCodec::Tabs& actual_pinned_tabs, |
| 31 const SessionStartupPref& backup_startup_pref, | 38 const SessionStartupPref& backup_startup_pref, |
| 32 const PinnedTabCodec::Tabs& backup_pinned_tabs); | 39 const PinnedTabCodec::Tabs& backup_pinned_tabs); |
| 33 | 40 |
| 34 // BaseSettingChange overrides: | 41 // BaseSettingChange overrides: |
| 35 virtual bool Init(Profile* profile) OVERRIDE; | 42 virtual bool Init(Profile* profile) OVERRIDE; |
| 36 virtual void Apply(Browser* browser) OVERRIDE; | 43 virtual void Apply(Browser* browser) OVERRIDE; |
| 37 virtual void Discard(Browser* browser) OVERRIDE; | 44 virtual void Discard(Browser* browser) OVERRIDE; |
| 38 virtual void Timeout() OVERRIDE; | 45 virtual void Timeout() OVERRIDE; |
| 39 virtual int GetBadgeIconID() const OVERRIDE; | 46 virtual int GetBadgeIconID() const OVERRIDE; |
| 40 virtual int GetMenuItemIconID() const OVERRIDE; | 47 virtual int GetMenuItemIconID() const OVERRIDE; |
| 41 virtual int GetBubbleIconID() const OVERRIDE; | 48 virtual int GetBubbleIconID() const OVERRIDE; |
| 42 virtual string16 GetBubbleTitle() const OVERRIDE; | 49 virtual string16 GetBubbleTitle() const OVERRIDE; |
| 43 virtual string16 GetBubbleMessage() const OVERRIDE; | 50 virtual string16 GetBubbleMessage() const OVERRIDE; |
| 44 virtual string16 GetApplyButtonText() const OVERRIDE; | 51 virtual string16 GetApplyButtonText() const OVERRIDE; |
| 45 virtual string16 GetDiscardButtonText() const OVERRIDE; | 52 virtual string16 GetDiscardButtonText() const OVERRIDE; |
| 53 virtual DisplayName GetApplyDisplayName() const OVERRIDE; | |
| 54 virtual std::string GetApplyKeyword() const OVERRIDE; | |
| 46 | 55 |
| 47 private: | 56 private: |
| 48 virtual ~SessionStartupChange(); | 57 virtual ~SessionStartupChange(); |
| 49 | 58 |
| 59 // Returns the first URL among new startup pages. Returns an empty URL if | |
| 60 // there are no new startup pages. | |
| 61 GURL GetFirstNewURL() const; | |
|
whywhat
2012/04/06 16:28:32
What if the first new URL is the same as the old o
Ivan Korotkov
2012/04/09 14:46:47
I considered that a non-common use case but you're
| |
| 62 | |
| 50 // Opens all tabs in |tabs| and makes them pinned. | 63 // Opens all tabs in |tabs| and makes them pinned. |
| 51 void OpenPinnedTabs(Browser* browser, const PinnedTabCodec::Tabs& tabs); | 64 void OpenPinnedTabs(Browser* browser, const PinnedTabCodec::Tabs& tabs); |
| 52 | 65 |
| 53 SessionStartupPref new_startup_pref_; | 66 SessionStartupPref new_startup_pref_; |
| 54 SessionStartupPref backup_startup_pref_; | 67 SessionStartupPref backup_startup_pref_; |
| 55 PinnedTabCodec::Tabs new_pinned_tabs_; | 68 PinnedTabCodec::Tabs new_pinned_tabs_; |
| 56 PinnedTabCodec::Tabs backup_pinned_tabs_; | 69 PinnedTabCodec::Tabs backup_pinned_tabs_; |
| 57 | 70 |
| 58 DISALLOW_COPY_AND_ASSIGN(SessionStartupChange); | 71 DISALLOW_COPY_AND_ASSIGN(SessionStartupChange); |
| 59 }; | 72 }; |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 132 } | 145 } |
| 133 | 146 |
| 134 string16 SessionStartupChange::GetBubbleMessage() const { | 147 string16 SessionStartupChange::GetBubbleMessage() const { |
| 135 return l10n_util::GetStringUTF16(IDS_STARTUP_SETTINGS_CHANGE_BUBBLE_MESSAGE); | 148 return l10n_util::GetStringUTF16(IDS_STARTUP_SETTINGS_CHANGE_BUBBLE_MESSAGE); |
| 136 } | 149 } |
| 137 | 150 |
| 138 string16 SessionStartupChange::GetApplyButtonText() const { | 151 string16 SessionStartupChange::GetApplyButtonText() const { |
| 139 if (new_startup_pref_.type == SessionStartupPref::LAST) | 152 if (new_startup_pref_.type == SessionStartupPref::LAST) |
| 140 return l10n_util::GetStringUTF16(IDS_CHANGE_STARTUP_SETTINGS_RESTORE); | 153 return l10n_util::GetStringUTF16(IDS_CHANGE_STARTUP_SETTINGS_RESTORE); |
| 141 | 154 |
| 142 string16 first_url; | 155 // Display the domain name of the first startup/pinned URL. |
| 143 if (new_startup_pref_.type == SessionStartupPref::URLS && | 156 string16 first_url = UTF8ToUTF16(GetFirstNewURL().host()); |
|
whywhat
2012/04/06 16:28:32
so is it first_url or first_url_host?
Ivan Korotkov
2012/04/09 14:46:47
Fixed.
| |
| 144 !new_startup_pref_.urls.empty()) { | |
| 145 // Display the domain name of the first statrup URL. | |
| 146 first_url = UTF8ToUTF16(new_startup_pref_.urls[0].host()); | |
| 147 } else if (!new_pinned_tabs_.empty()) { | |
| 148 // Start with NTP or no URLs (basically the same): display the domain name | |
| 149 // of the first pinned tab, if any. | |
| 150 first_url = UTF8ToUTF16(new_pinned_tabs_[0].url.host()); | |
| 151 } | |
| 152 return first_url.empty() ? | 157 return first_url.empty() ? |
| 153 l10n_util::GetStringUTF16(IDS_CHANGE_STARTUP_SETTINGS_NTP) : | 158 l10n_util::GetStringUTF16(IDS_CHANGE_STARTUP_SETTINGS_NTP) : |
| 154 l10n_util::GetStringFUTF16(IDS_CHANGE_STARTUP_SETTINGS_URLS, | 159 l10n_util::GetStringFUTF16(IDS_CHANGE_STARTUP_SETTINGS_URLS, |
| 155 first_url); | 160 first_url); |
| 156 } | 161 } |
| 157 | 162 |
| 158 string16 SessionStartupChange::GetDiscardButtonText() const { | 163 string16 SessionStartupChange::GetDiscardButtonText() const { |
| 159 return l10n_util::GetStringUTF16(IDS_KEEP_SETTING); | 164 return l10n_util::GetStringUTF16(IDS_KEEP_SETTING); |
| 160 } | 165 } |
| 161 | 166 |
| 167 BaseSettingChange::DisplayName | |
| 168 SessionStartupChange::GetApplyDisplayName() const { | |
| 169 string16 first_url = UTF8ToUTF16(GetFirstNewURL().host()); | |
| 170 return first_url.empty() ? DisplayName(kDefaultNamePriority, string16()) : | |
| 171 DisplayName(kNamePriority, first_url); | |
| 172 } | |
| 173 | |
| 174 std::string SessionStartupChange::GetApplyKeyword() const { | |
| 175 return GetFirstNewURL().host(); | |
| 176 } | |
| 177 | |
| 178 GURL SessionStartupChange::GetFirstNewURL() const { | |
|
whywhat
2012/04/06 16:28:32
I guess it could return .host() since it's what ev
Ivan Korotkov
2012/04/09 14:46:47
Done.
| |
| 179 if (new_startup_pref_.type == SessionStartupPref::URLS && | |
| 180 !new_startup_pref_.urls.empty()) { | |
| 181 return new_startup_pref_.urls[0]; | |
| 182 } | |
| 183 if (!new_pinned_tabs_.empty()) | |
| 184 return new_pinned_tabs_[0].url; | |
| 185 return GURL(); | |
| 186 } | |
| 187 | |
| 162 void SessionStartupChange::OpenPinnedTabs( | 188 void SessionStartupChange::OpenPinnedTabs( |
| 163 Browser* browser, | 189 Browser* browser, |
| 164 const PinnedTabCodec::Tabs& tabs) { | 190 const PinnedTabCodec::Tabs& tabs) { |
| 165 for (size_t i = 0; i < tabs.size(); ++i) { | 191 for (size_t i = 0; i < tabs.size(); ++i) { |
| 166 browser::NavigateParams params(browser, tabs[i].url, | 192 browser::NavigateParams params(browser, tabs[i].url, |
| 167 content::PAGE_TRANSITION_START_PAGE); | 193 content::PAGE_TRANSITION_START_PAGE); |
| 168 params.disposition = NEW_BACKGROUND_TAB; | 194 params.disposition = NEW_BACKGROUND_TAB; |
| 169 params.tabstrip_index = -1; | 195 params.tabstrip_index = -1; |
| 170 params.tabstrip_add_types = TabStripModel::ADD_PINNED; | 196 params.tabstrip_add_types = TabStripModel::ADD_PINNED; |
| 171 params.extension_app_id = tabs[i].app_id; | 197 params.extension_app_id = tabs[i].app_id; |
| 172 browser::Navigate(¶ms); | 198 browser::Navigate(¶ms); |
| 173 } | 199 } |
| 174 } | 200 } |
| 175 | 201 |
| 176 BaseSettingChange* CreateSessionStartupChange( | 202 BaseSettingChange* CreateSessionStartupChange( |
| 177 const SessionStartupPref& actual_startup_pref, | 203 const SessionStartupPref& actual_startup_pref, |
| 178 const PinnedTabCodec::Tabs& actual_pinned_tabs, | 204 const PinnedTabCodec::Tabs& actual_pinned_tabs, |
| 179 const SessionStartupPref& backup_startup_pref, | 205 const SessionStartupPref& backup_startup_pref, |
| 180 const PinnedTabCodec::Tabs& backup_pinned_tabs) { | 206 const PinnedTabCodec::Tabs& backup_pinned_tabs) { |
| 181 return new SessionStartupChange(actual_startup_pref, actual_pinned_tabs, | 207 return new SessionStartupChange(actual_startup_pref, actual_pinned_tabs, |
| 182 backup_startup_pref, backup_pinned_tabs); | 208 backup_startup_pref, backup_pinned_tabs); |
| 183 } | 209 } |
| 184 | 210 |
| 185 } // namespace protector | 211 } // namespace protector |
| OLD | NEW |