Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: chrome/browser/ui/browser_init.cc

Issue 7692009: Fixes crash when clicking session restore button on info bar. The (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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_init.h" 5 #include "chrome/browser/ui/browser_init.h"
6 6
7 #include <algorithm> // For max(). 7 #include <algorithm> // For max().
8 8
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/environment.h" 10 #include "base/environment.h"
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 291 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
292 new NotifyNotDefaultBrowserTask()); 292 new NotifyNotDefaultBrowserTask());
293 } 293 }
294 294
295 295
296 // SessionCrashedInfoBarDelegate ---------------------------------------------- 296 // SessionCrashedInfoBarDelegate ----------------------------------------------
297 297
298 // A delegate for the InfoBar shown when the previous session has crashed. 298 // A delegate for the InfoBar shown when the previous session has crashed.
299 class SessionCrashedInfoBarDelegate : public ConfirmInfoBarDelegate { 299 class SessionCrashedInfoBarDelegate : public ConfirmInfoBarDelegate {
300 public: 300 public:
301 SessionCrashedInfoBarDelegate(Browser* browser, TabContents* contents); 301 SessionCrashedInfoBarDelegate(Profile* profile, TabContents* contents);
302 302
303 private: 303 private:
304 virtual ~SessionCrashedInfoBarDelegate(); 304 virtual ~SessionCrashedInfoBarDelegate();
305 305
306 // ConfirmInfoBarDelegate: 306 // ConfirmInfoBarDelegate:
307 virtual gfx::Image* GetIcon() const OVERRIDE; 307 virtual gfx::Image* GetIcon() const OVERRIDE;
308 virtual string16 GetMessageText() const OVERRIDE; 308 virtual string16 GetMessageText() const OVERRIDE;
309 virtual int GetButtons() const OVERRIDE; 309 virtual int GetButtons() const OVERRIDE;
310 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; 310 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE;
311 virtual bool Accept() OVERRIDE; 311 virtual bool Accept() OVERRIDE;
312 312
313 Browser* browser_;
314
315 // The Profile that we restore sessions from. 313 // The Profile that we restore sessions from.
316 Profile* profile_; 314 Profile* profile_;
317 315
318 DISALLOW_COPY_AND_ASSIGN(SessionCrashedInfoBarDelegate); 316 DISALLOW_COPY_AND_ASSIGN(SessionCrashedInfoBarDelegate);
319 }; 317 };
320 318
321 SessionCrashedInfoBarDelegate::SessionCrashedInfoBarDelegate( 319 SessionCrashedInfoBarDelegate::SessionCrashedInfoBarDelegate(
322 Browser* browser, 320 Profile* profile,
323 TabContents* contents) 321 TabContents* contents)
324 : ConfirmInfoBarDelegate(contents), 322 : ConfirmInfoBarDelegate(contents),
325 browser_(browser), 323 profile_(profile) {
326 profile_(Profile::FromBrowserContext(contents->browser_context())) {
327 } 324 }
328 325
329 SessionCrashedInfoBarDelegate::~SessionCrashedInfoBarDelegate() { 326 SessionCrashedInfoBarDelegate::~SessionCrashedInfoBarDelegate() {
330 } 327 }
331 328
332 gfx::Image* SessionCrashedInfoBarDelegate::GetIcon() const { 329 gfx::Image* SessionCrashedInfoBarDelegate::GetIcon() const {
333 return &ResourceBundle::GetSharedInstance().GetNativeImageNamed( 330 return &ResourceBundle::GetSharedInstance().GetNativeImageNamed(
334 IDR_INFOBAR_RESTORE_SESSION); 331 IDR_INFOBAR_RESTORE_SESSION);
335 } 332 }
336 333
337 string16 SessionCrashedInfoBarDelegate::GetMessageText() const { 334 string16 SessionCrashedInfoBarDelegate::GetMessageText() const {
338 return l10n_util::GetStringUTF16(IDS_SESSION_CRASHED_VIEW_MESSAGE); 335 return l10n_util::GetStringUTF16(IDS_SESSION_CRASHED_VIEW_MESSAGE);
339 } 336 }
340 337
341 int SessionCrashedInfoBarDelegate::GetButtons() const { 338 int SessionCrashedInfoBarDelegate::GetButtons() const {
342 return BUTTON_OK; 339 return BUTTON_OK;
343 } 340 }
344 341
345 string16 SessionCrashedInfoBarDelegate::GetButtonLabel( 342 string16 SessionCrashedInfoBarDelegate::GetButtonLabel(
346 InfoBarButton button) const { 343 InfoBarButton button) const {
347 DCHECK_EQ(BUTTON_OK, button); 344 DCHECK_EQ(BUTTON_OK, button);
348 return l10n_util::GetStringUTF16(IDS_SESSION_CRASHED_VIEW_RESTORE_BUTTON); 345 return l10n_util::GetStringUTF16(IDS_SESSION_CRASHED_VIEW_RESTORE_BUTTON);
349 } 346 }
350 347
351 bool SessionCrashedInfoBarDelegate::Accept() { 348 bool SessionCrashedInfoBarDelegate::Accept() {
352 uint32 behavior = 0; 349 uint32 behavior = 0;
353 if (browser_->tab_count() == 1 && browser_->GetTabContentsAt(0)->GetURL() == 350 Browser* browser = BrowserList::GetLastActiveWithProfile(profile_);
351 if (browser && browser->tab_count() == 1
352 && browser->GetTabContentsAt(0)->GetURL() ==
354 GURL(chrome::kChromeUINewTabURL)) { 353 GURL(chrome::kChromeUINewTabURL)) {
355 // There is only one tab and its the new tab page, make session restore 354 // There is only one tab and its the new tab page, make session restore
356 // clobber it. 355 // clobber it.
357 behavior = SessionRestore::CLOBBER_CURRENT_TAB; 356 behavior = SessionRestore::CLOBBER_CURRENT_TAB;
358 } 357 }
359 SessionRestore::RestoreSession( 358 SessionRestore::RestoreSession(
360 profile_, browser_, behavior, std::vector<GURL>()); 359 profile_, browser, behavior, std::vector<GURL>());
361 return true; 360 return true;
362 } 361 }
363 362
364 363
365 // Utility functions ---------------------------------------------------------- 364 // Utility functions ----------------------------------------------------------
366 365
367 bool IncognitoIsForced(const CommandLine& command_line, 366 bool IncognitoIsForced(const CommandLine& command_line,
368 const PrefService* prefs) { 367 const PrefService* prefs) {
369 IncognitoModePrefs::Availability incognito_avail = 368 IncognitoModePrefs::Availability incognito_avail =
370 IncognitoModePrefs::GetAvailability(prefs); 369 IncognitoModePrefs::GetAvailability(prefs);
(...skipping 707 matching lines...) Expand 10 before | Expand all | Expand 10 after
1078 AddBadFlagsInfoBarIfNecessary(tab_contents); 1077 AddBadFlagsInfoBarIfNecessary(tab_contents);
1079 AddDNSCertProvenanceCheckingWarningInfoBarIfNecessary(tab_contents); 1078 AddDNSCertProvenanceCheckingWarningInfoBarIfNecessary(tab_contents);
1080 AddObsoleteSystemInfoBarIfNecessary(tab_contents); 1079 AddObsoleteSystemInfoBarIfNecessary(tab_contents);
1081 } 1080 }
1082 1081
1083 void BrowserInit::LaunchWithProfile::AddCrashedInfoBarIfNecessary( 1082 void BrowserInit::LaunchWithProfile::AddCrashedInfoBarIfNecessary(
1084 Browser* browser, 1083 Browser* browser,
1085 TabContentsWrapper* tab) { 1084 TabContentsWrapper* tab) {
1086 // Assume that if the user is launching incognito they were previously 1085 // Assume that if the user is launching incognito they were previously
1087 // running incognito so that we have nothing to restore from. 1086 // running incognito so that we have nothing to restore from.
1088 if (!profile_->DidLastSessionExitCleanly() && 1087 if (!profile_->DidLastSessionExitCleanly() && !profile_->IsOffTheRecord()) {
1089 !profile_->IsOffTheRecord()) {
1090 // The last session didn't exit cleanly. Show an infobar to the user 1088 // The last session didn't exit cleanly. Show an infobar to the user
1091 // so that they can restore if they want. The delegate deletes itself when 1089 // so that they can restore if they want. The delegate deletes itself when
1092 // it is closed. 1090 // it is closed.
1093 tab->AddInfoBar( 1091 tab->AddInfoBar(
1094 new SessionCrashedInfoBarDelegate(browser, tab->tab_contents())); 1092 new SessionCrashedInfoBarDelegate(profile_, tab->tab_contents()));
1095 } 1093 }
1096 } 1094 }
1097 1095
1098 void BrowserInit::LaunchWithProfile::AddBadFlagsInfoBarIfNecessary( 1096 void BrowserInit::LaunchWithProfile::AddBadFlagsInfoBarIfNecessary(
1099 TabContentsWrapper* tab) { 1097 TabContentsWrapper* tab) {
1100 // Unsupported flags for which to display a warning that "stability and 1098 // Unsupported flags for which to display a warning that "stability and
1101 // security will suffer". 1099 // security will suffer".
1102 static const char* kBadFlags[] = { 1100 static const char* kBadFlags[] = {
1103 // These imply disabling the sandbox. 1101 // These imply disabling the sandbox.
1104 switches::kSingleProcess, 1102 switches::kSingleProcess,
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after
1480 return false; 1478 return false;
1481 automation->SetExpectedTabCount(expected_tabs); 1479 automation->SetExpectedTabCount(expected_tabs);
1482 1480
1483 AutomationProviderList* list = 1481 AutomationProviderList* list =
1484 g_browser_process->InitAutomationProviderList(); 1482 g_browser_process->InitAutomationProviderList();
1485 DCHECK(list); 1483 DCHECK(list);
1486 list->AddProvider(automation); 1484 list->AddProvider(automation);
1487 1485
1488 return true; 1486 return true;
1489 } 1487 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698