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

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

Issue 490019: Show an infobar when the user is using an unsupported flag. (Closed)
Patch Set: logic bug Created 11 years 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
« no previous file with comments | « chrome/browser/browser_init.h ('k') | 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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/browser_init.h" 5 #include "chrome/browser/browser_init.h"
6 6
7 #include "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "app/resource_bundle.h" 8 #include "app/resource_bundle.h"
9 #include "base/event_recorder.h" 9 #include "base/event_recorder.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 ChromeThread::PostTask( 193 ChromeThread::PostTask(
194 ChromeThread::UI, FROM_HERE, new NotifyNotDefaultBrowserTask()); 194 ChromeThread::UI, FROM_HERE, new NotifyNotDefaultBrowserTask());
195 } 195 }
196 196
197 private: 197 private:
198 DISALLOW_COPY_AND_ASSIGN(CheckDefaultBrowserTask); 198 DISALLOW_COPY_AND_ASSIGN(CheckDefaultBrowserTask);
199 }; 199 };
200 200
201 // A delegate for the InfoBar shown when the previous session has crashed. The 201 // A delegate for the InfoBar shown when the previous session has crashed. The
202 // bar deletes itself automatically after it is closed. 202 // bar deletes itself automatically after it is closed.
203 // TODO(timsteele): This delegate can leak when a tab is closed, see
204 // http://crbug.com/6520
205 class SessionCrashedInfoBarDelegate : public ConfirmInfoBarDelegate { 203 class SessionCrashedInfoBarDelegate : public ConfirmInfoBarDelegate {
206 public: 204 public:
207 explicit SessionCrashedInfoBarDelegate(TabContents* contents) 205 explicit SessionCrashedInfoBarDelegate(TabContents* contents)
208 : ConfirmInfoBarDelegate(contents), 206 : ConfirmInfoBarDelegate(contents),
209 profile_(contents->profile()) { 207 profile_(contents->profile()) {
210 } 208 }
211 209
212 // Overridden from ConfirmInfoBarDelegate: 210 // Overridden from ConfirmInfoBarDelegate:
213 virtual void InfoBarClosed() { 211 virtual void InfoBarClosed() {
214 delete this; 212 delete this;
(...skipping 16 matching lines...) Expand all
231 return true; 229 return true;
232 } 230 }
233 231
234 private: 232 private:
235 // The Profile that we restore sessions from. 233 // The Profile that we restore sessions from.
236 Profile* profile_; 234 Profile* profile_;
237 235
238 DISALLOW_COPY_AND_ASSIGN(SessionCrashedInfoBarDelegate); 236 DISALLOW_COPY_AND_ASSIGN(SessionCrashedInfoBarDelegate);
239 }; 237 };
240 238
239 // A delegate for the InfoBar shown when you're using unsupported
240 // command-line flags. The bar deletes itself automatically after it
241 // is closed.
242 class BadFlagsInfoBarDelegate : public AlertInfoBarDelegate {
243 public:
244 explicit BadFlagsInfoBarDelegate(TabContents* contents, const char* flag)
245 : AlertInfoBarDelegate(contents), flag_(flag) {
246 }
247
248 virtual bool ShouldExpire(
249 const NavigationController::LoadCommittedDetails& details) const {
250 // Require explicit closure by the user.
251 return false;
252 }
253
254 virtual void InfoBarClosed() {
255 delete this;
256 }
257
258 virtual std::wstring GetMessageText() const {
259 // Since our flag names are in English anyway, I don't think we should
viettrungluu 2009/12/11 19:15:51 Surely people can use flags even if they don't und
260 // make this string translatable.
261 return ASCIIToWide(
262 StringPrintf("You are using an unsupported command-line flag: --%s. "
viettrungluu 2009/12/11 19:15:51 I'm sceptical that there should be two spaces afte
Evan Martin 2009/12/11 19:18:45 Religious debate! :P I will change it. Habit.
263 "Stability and security will suffer.",
264 flag_));
265 }
266
267 private:
268 // The flag that we're complaining about.
269 const char* flag_;
270
271 DISALLOW_COPY_AND_ASSIGN(BadFlagsInfoBarDelegate);
272 };
273
241 SessionStartupPref GetSessionStartupPref(const CommandLine& command_line, 274 SessionStartupPref GetSessionStartupPref(const CommandLine& command_line,
242 Profile* profile) { 275 Profile* profile) {
243 SessionStartupPref pref = SessionStartupPref::GetStartupPref(profile); 276 SessionStartupPref pref = SessionStartupPref::GetStartupPref(profile);
244 if (command_line.HasSwitch(switches::kRestoreLastSession)) 277 if (command_line.HasSwitch(switches::kRestoreLastSession))
245 pref.type = SessionStartupPref::LAST; 278 pref.type = SessionStartupPref::LAST;
246 if (command_line.HasSwitch(switches::kIncognito) && 279 if (command_line.HasSwitch(switches::kIncognito) &&
247 pref.type == SessionStartupPref::LAST) { 280 pref.type == SessionStartupPref::LAST) {
248 // We don't store session information when incognito. If the user has 281 // We don't store session information when incognito. If the user has
249 // chosen to restore last session and launched incognito, fallback to 282 // chosen to restore last session and launched incognito, fallback to
250 // default launch behavior. 283 // default launch behavior.
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 // We skip URLs that we'd have to launch an external protocol handler for. 613 // We skip URLs that we'd have to launch an external protocol handler for.
581 // This avoids us getting into an infinite loop asking ourselves to open 614 // This avoids us getting into an infinite loop asking ourselves to open
582 // a URL, should the handler be (incorrectly) configured to be us. Anyone 615 // a URL, should the handler be (incorrectly) configured to be us. Anyone
583 // asking us to open such a URL should really ask the handler directly. 616 // asking us to open such a URL should really ask the handler directly.
584 if (!process_startup && !URLRequest::IsHandledURL(urls[i])) 617 if (!process_startup && !URLRequest::IsHandledURL(urls[i]))
585 continue; 618 continue;
586 TabContents* tab = browser->AddTabWithURL( 619 TabContents* tab = browser->AddTabWithURL(
587 urls[i], GURL(), PageTransition::START_PAGE, (i == 0), -1, false, NULL); 620 urls[i], GURL(), PageTransition::START_PAGE, (i == 0), -1, false, NULL);
588 if (i < static_cast<size_t>(pin_count)) 621 if (i < static_cast<size_t>(pin_count))
589 browser->tabstrip_model()->SetTabPinned(browser->tab_count() - 1, true); 622 browser->tabstrip_model()->SetTabPinned(browser->tab_count() - 1, true);
590 if (profile_ && i == 0 && process_startup) 623
591 AddCrashedInfoBarIfNecessary(tab); 624 if (i == 0 && process_startup) {
viettrungluu 2009/12/11 19:15:51 I would slightly prefer if it were "process_startu
Evan Martin 2009/12/11 19:18:45 I was matching the existing code, which I think do
viettrungluu 2009/12/11 19:45:40 Fair enough. I definitely don't insist.
625 // First tab; attach necessary InfoBars to it.
626 if (profile_)
627 AddCrashedInfoBarIfNecessary(tab);
628 AddBadFlagsInfoBarIfNecessary(tab);
629 }
592 } 630 }
593 browser->window()->Show(); 631 browser->window()->Show();
594 // TODO(jcampan): http://crbug.com/8123 we should not need to set the initial 632 // TODO(jcampan): http://crbug.com/8123 we should not need to set the initial
595 // focus explicitly. 633 // focus explicitly.
596 browser->GetSelectedTabContents()->view()->SetInitialFocus(); 634 browser->GetSelectedTabContents()->view()->SetInitialFocus();
597 635
598 return browser; 636 return browser;
599 } 637 }
600 638
601 void BrowserInit::LaunchWithProfile::AddCrashedInfoBarIfNecessary( 639 void BrowserInit::LaunchWithProfile::AddCrashedInfoBarIfNecessary(
602 TabContents* tab) { 640 TabContents* tab) {
603 // Assume that if the user is launching incognito they were previously 641 // Assume that if the user is launching incognito they were previously
604 // running incognito so that we have nothing to restore from. 642 // running incognito so that we have nothing to restore from.
605 if (!profile_->DidLastSessionExitCleanly() && 643 if (!profile_->DidLastSessionExitCleanly() &&
606 !profile_->IsOffTheRecord()) { 644 !profile_->IsOffTheRecord()) {
607 // The last session didn't exit cleanly. Show an infobar to the user 645 // The last session didn't exit cleanly. Show an infobar to the user
608 // so that they can restore if they want. The delegate deletes itself when 646 // so that they can restore if they want. The delegate deletes itself when
609 // it is closed. 647 // it is closed.
610 tab->AddInfoBar(new SessionCrashedInfoBarDelegate(tab)); 648 tab->AddInfoBar(new SessionCrashedInfoBarDelegate(tab));
611 } 649 }
612 } 650 }
613 651
652 void BrowserInit::LaunchWithProfile::AddBadFlagsInfoBarIfNecessary(
653 TabContents* tab) {
654 static const char* kBadFlags[] = {
655 switches::kSingleProcess,
656 switches::kNoSandbox,
657 NULL
658 };
659
660 const char* bad_flag = NULL;
661 for (const char** flag = kBadFlags; *flag; ++flag) {
662 if (command_line_.HasSwitch(*flag)) {
663 bad_flag = *flag;
viettrungluu 2009/12/11 19:15:51 I'm a little disappointed that you only warn of at
Evan Martin 2009/12/11 19:18:45 You run out of space in the infobar otherwise.
Mohamed Mansour 2009/12/11 19:42:35 This is good that way, because we can put many Bad
viettrungluu 2009/12/11 19:45:40 Good point.
664 break;
665 }
666 }
667
668 if (bad_flag)
669 tab->AddInfoBar(new BadFlagsInfoBarDelegate(tab, bad_flag));
670 }
671
614 std::vector<GURL> BrowserInit::LaunchWithProfile::GetURLsFromCommandLine( 672 std::vector<GURL> BrowserInit::LaunchWithProfile::GetURLsFromCommandLine(
615 Profile* profile) { 673 Profile* profile) {
616 std::vector<GURL> urls; 674 std::vector<GURL> urls;
617 std::vector<std::wstring> params = command_line_.GetLooseValues(); 675 std::vector<std::wstring> params = command_line_.GetLooseValues();
618 for (size_t i = 0; i < params.size(); ++i) { 676 for (size_t i = 0; i < params.size(); ++i) {
619 std::wstring& value = params[i]; 677 std::wstring& value = params[i];
620 // Handle Vista way of searching - "? <search-term>" 678 // Handle Vista way of searching - "? <search-term>"
621 if (value.find(L"? ") == 0) { 679 if (value.find(L"? ") == 0) {
622 const TemplateURL* default_provider = 680 const TemplateURL* default_provider =
623 profile->GetTemplateURLModel()->GetDefaultSearchProvider(); 681 profile->GetTemplateURLModel()->GetDefaultSearchProvider();
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
852 scoped_refptr<AutomationProviderClass> automation = 910 scoped_refptr<AutomationProviderClass> automation =
853 new AutomationProviderClass(profile); 911 new AutomationProviderClass(profile);
854 automation->ConnectToChannel(channel_id); 912 automation->ConnectToChannel(channel_id);
855 automation->SetExpectedTabCount(expected_tabs); 913 automation->SetExpectedTabCount(expected_tabs);
856 914
857 AutomationProviderList* list = 915 AutomationProviderList* list =
858 g_browser_process->InitAutomationProviderList(); 916 g_browser_process->InitAutomationProviderList();
859 DCHECK(list); 917 DCHECK(list);
860 list->AddProvider(automation); 918 list->AddProvider(automation);
861 } 919 }
OLDNEW
« no previous file with comments | « chrome/browser/browser_init.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698