| 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" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 virtual void Apply(Browser* browser) OVERRIDE; | 36 virtual void Apply(Browser* browser) OVERRIDE; |
| 37 virtual void Discard(Browser* browser) OVERRIDE; | 37 virtual void Discard(Browser* browser) OVERRIDE; |
| 38 virtual void Timeout() OVERRIDE; | 38 virtual void Timeout() OVERRIDE; |
| 39 virtual int GetBadgeIconID() const OVERRIDE; | 39 virtual int GetBadgeIconID() const OVERRIDE; |
| 40 virtual int GetMenuItemIconID() const OVERRIDE; | 40 virtual int GetMenuItemIconID() const OVERRIDE; |
| 41 virtual int GetBubbleIconID() const OVERRIDE; | 41 virtual int GetBubbleIconID() const OVERRIDE; |
| 42 virtual string16 GetBubbleTitle() const OVERRIDE; | 42 virtual string16 GetBubbleTitle() const OVERRIDE; |
| 43 virtual string16 GetBubbleMessage() const OVERRIDE; | 43 virtual string16 GetBubbleMessage() const OVERRIDE; |
| 44 virtual string16 GetApplyButtonText() const OVERRIDE; | 44 virtual string16 GetApplyButtonText() const OVERRIDE; |
| 45 virtual string16 GetDiscardButtonText() const OVERRIDE; | 45 virtual string16 GetDiscardButtonText() const OVERRIDE; |
| 46 virtual DisplayName GetApplyDisplayName() const OVERRIDE; |
| 47 virtual GURL GetNewSettingURL() const OVERRIDE; |
| 46 | 48 |
| 47 private: | 49 private: |
| 48 virtual ~SessionStartupChange(); | 50 virtual ~SessionStartupChange(); |
| 49 | 51 |
| 52 // Returns the first URL among new startup pages. Returns an empty URL if |
| 53 // there are no new startup pages. |
| 54 GURL GetFirstNewURL() const; |
| 55 |
| 50 // Opens all tabs in |tabs| and makes them pinned. | 56 // Opens all tabs in |tabs| and makes them pinned. |
| 51 void OpenPinnedTabs(Browser* browser, const PinnedTabCodec::Tabs& tabs); | 57 void OpenPinnedTabs(Browser* browser, const PinnedTabCodec::Tabs& tabs); |
| 52 | 58 |
| 53 SessionStartupPref new_startup_pref_; | 59 SessionStartupPref new_startup_pref_; |
| 54 SessionStartupPref backup_startup_pref_; | 60 SessionStartupPref backup_startup_pref_; |
| 55 PinnedTabCodec::Tabs new_pinned_tabs_; | 61 PinnedTabCodec::Tabs new_pinned_tabs_; |
| 56 PinnedTabCodec::Tabs backup_pinned_tabs_; | 62 PinnedTabCodec::Tabs backup_pinned_tabs_; |
| 57 | 63 |
| 58 DISALLOW_COPY_AND_ASSIGN(SessionStartupChange); | 64 DISALLOW_COPY_AND_ASSIGN(SessionStartupChange); |
| 59 }; | 65 }; |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 } | 138 } |
| 133 | 139 |
| 134 string16 SessionStartupChange::GetBubbleMessage() const { | 140 string16 SessionStartupChange::GetBubbleMessage() const { |
| 135 return l10n_util::GetStringUTF16(IDS_STARTUP_SETTINGS_CHANGE_BUBBLE_MESSAGE); | 141 return l10n_util::GetStringUTF16(IDS_STARTUP_SETTINGS_CHANGE_BUBBLE_MESSAGE); |
| 136 } | 142 } |
| 137 | 143 |
| 138 string16 SessionStartupChange::GetApplyButtonText() const { | 144 string16 SessionStartupChange::GetApplyButtonText() const { |
| 139 if (new_startup_pref_.type == SessionStartupPref::LAST) | 145 if (new_startup_pref_.type == SessionStartupPref::LAST) |
| 140 return l10n_util::GetStringUTF16(IDS_CHANGE_STARTUP_SETTINGS_RESTORE); | 146 return l10n_util::GetStringUTF16(IDS_CHANGE_STARTUP_SETTINGS_RESTORE); |
| 141 | 147 |
| 142 string16 first_url; | 148 // Display the domain name of the first startup/pinned URL. |
| 143 if (new_startup_pref_.type == SessionStartupPref::URLS && | 149 string16 first_domain = UTF8ToUTF16(GetFirstNewURL().host()); |
| 144 !new_startup_pref_.urls.empty()) { | 150 return first_domain.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() ? | |
| 153 l10n_util::GetStringUTF16(IDS_CHANGE_STARTUP_SETTINGS_NTP) : | 151 l10n_util::GetStringUTF16(IDS_CHANGE_STARTUP_SETTINGS_NTP) : |
| 154 l10n_util::GetStringFUTF16(IDS_CHANGE_STARTUP_SETTINGS_URLS, | 152 l10n_util::GetStringFUTF16(IDS_CHANGE_STARTUP_SETTINGS_URLS, |
| 155 first_url); | 153 first_domain); |
| 156 } | 154 } |
| 157 | 155 |
| 158 string16 SessionStartupChange::GetDiscardButtonText() const { | 156 string16 SessionStartupChange::GetDiscardButtonText() const { |
| 159 return l10n_util::GetStringUTF16(IDS_KEEP_SETTING); | 157 return l10n_util::GetStringUTF16(IDS_KEEP_SETTING); |
| 160 } | 158 } |
| 161 | 159 |
| 160 BaseSettingChange::DisplayName |
| 161 SessionStartupChange::GetApplyDisplayName() const { |
| 162 string16 first_domain = UTF8ToUTF16(GetFirstNewURL().host()); |
| 163 return first_domain.empty() ? |
| 164 BaseSettingChange::GetApplyDisplayName() : |
| 165 DisplayName(kSessionStartupChangeNamePriority, first_domain); |
| 166 } |
| 167 |
| 168 GURL SessionStartupChange::GetNewSettingURL() const { |
| 169 VLOG(1) << "HP URL: " << GetFirstNewURL().spec(); |
| 170 return GetFirstNewURL(); |
| 171 } |
| 172 |
| 173 GURL SessionStartupChange::GetFirstNewURL() const { |
| 174 // TODO(ivankr): this actually should return the first URL present in new |
| 175 // startup prefs AND not in old. |
| 176 if (new_startup_pref_.type == SessionStartupPref::URLS && |
| 177 !new_startup_pref_.urls.empty()) { |
| 178 return new_startup_pref_.urls[0]; |
| 179 } |
| 180 if (!new_pinned_tabs_.empty()) |
| 181 return new_pinned_tabs_[0].url; |
| 182 return GURL(); |
| 183 } |
| 184 |
| 162 void SessionStartupChange::OpenPinnedTabs( | 185 void SessionStartupChange::OpenPinnedTabs( |
| 163 Browser* browser, | 186 Browser* browser, |
| 164 const PinnedTabCodec::Tabs& tabs) { | 187 const PinnedTabCodec::Tabs& tabs) { |
| 165 for (size_t i = 0; i < tabs.size(); ++i) { | 188 for (size_t i = 0; i < tabs.size(); ++i) { |
| 166 browser::NavigateParams params(browser, tabs[i].url, | 189 browser::NavigateParams params(browser, tabs[i].url, |
| 167 content::PAGE_TRANSITION_START_PAGE); | 190 content::PAGE_TRANSITION_START_PAGE); |
| 168 params.disposition = NEW_BACKGROUND_TAB; | 191 params.disposition = NEW_BACKGROUND_TAB; |
| 169 params.tabstrip_index = -1; | 192 params.tabstrip_index = -1; |
| 170 params.tabstrip_add_types = TabStripModel::ADD_PINNED; | 193 params.tabstrip_add_types = TabStripModel::ADD_PINNED; |
| 171 params.extension_app_id = tabs[i].app_id; | 194 params.extension_app_id = tabs[i].app_id; |
| 172 browser::Navigate(¶ms); | 195 browser::Navigate(¶ms); |
| 173 } | 196 } |
| 174 } | 197 } |
| 175 | 198 |
| 176 BaseSettingChange* CreateSessionStartupChange( | 199 BaseSettingChange* CreateSessionStartupChange( |
| 177 const SessionStartupPref& actual_startup_pref, | 200 const SessionStartupPref& actual_startup_pref, |
| 178 const PinnedTabCodec::Tabs& actual_pinned_tabs, | 201 const PinnedTabCodec::Tabs& actual_pinned_tabs, |
| 179 const SessionStartupPref& backup_startup_pref, | 202 const SessionStartupPref& backup_startup_pref, |
| 180 const PinnedTabCodec::Tabs& backup_pinned_tabs) { | 203 const PinnedTabCodec::Tabs& backup_pinned_tabs) { |
| 181 return new SessionStartupChange(actual_startup_pref, actual_pinned_tabs, | 204 return new SessionStartupChange(actual_startup_pref, actual_pinned_tabs, |
| 182 backup_startup_pref, backup_pinned_tabs); | 205 backup_startup_pref, backup_pinned_tabs); |
| 183 } | 206 } |
| 184 | 207 |
| 185 } // namespace protector | 208 } // namespace protector |
| OLD | NEW |