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

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

Issue 10702029: Move tab functions off Browser into browser_tabstrip and browser_tabrestore. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 5 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
OLDNEW
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 "chrome/browser/ui/browser_commands.h" 5 #include "chrome/browser/ui/browser_commands.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.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/bookmarks/bookmark_editor.h" 10 #include "chrome/browser/bookmarks/bookmark_editor.h"
(...skipping 13 matching lines...) Expand all
24 #include "chrome/browser/printing/print_view_manager.h" 24 #include "chrome/browser/printing/print_view_manager.h"
25 #include "chrome/browser/profiles/profile.h" 25 #include "chrome/browser/profiles/profile.h"
26 #include "chrome/browser/sessions/session_service_factory.h" 26 #include "chrome/browser/sessions/session_service_factory.h"
27 #include "chrome/browser/sessions/tab_restore_service_factory.h" 27 #include "chrome/browser/sessions/tab_restore_service_factory.h"
28 #include "chrome/browser/sessions/tab_restore_service.h" 28 #include "chrome/browser/sessions/tab_restore_service.h"
29 #include "chrome/browser/sessions/tab_restore_service_delegate.h" 29 #include "chrome/browser/sessions/tab_restore_service_delegate.h"
30 #include "chrome/browser/ui/browser.h" 30 #include "chrome/browser/ui/browser.h"
31 #include "chrome/browser/ui/browser_command_controller.h" 31 #include "chrome/browser/ui/browser_command_controller.h"
32 #include "chrome/browser/ui/browser_finder.h" 32 #include "chrome/browser/ui/browser_finder.h"
33 #include "chrome/browser/ui/browser_tab_restore_service_delegate.h" 33 #include "chrome/browser/ui/browser_tab_restore_service_delegate.h"
34 #include "chrome/browser/ui/browser_tabstrip.h"
34 #include "chrome/browser/ui/browser_window.h" 35 #include "chrome/browser/ui/browser_window.h"
35 #include "chrome/browser/ui/constrained_window_tab_helper.h" 36 #include "chrome/browser/ui/constrained_window_tab_helper.h"
36 #include "chrome/browser/ui/find_bar/find_bar_controller.h" 37 #include "chrome/browser/ui/find_bar/find_bar_controller.h"
37 #include "chrome/browser/ui/find_bar/find_tab_helper.h" 38 #include "chrome/browser/ui/find_bar/find_tab_helper.h"
38 #include "chrome/browser/ui/omnibox/location_bar.h" 39 #include "chrome/browser/ui/omnibox/location_bar.h"
39 #include "chrome/browser/ui/search/search.h" 40 #include "chrome/browser/ui/search/search.h"
40 #include "chrome/browser/ui/search/search_model.h" 41 #include "chrome/browser/ui/search/search_model.h"
41 #include "chrome/browser/ui/status_bubble.h" 42 #include "chrome/browser/ui/status_bubble.h"
42 #include "chrome/browser/ui/tab_contents/tab_contents.h" 43 #include "chrome/browser/ui/tab_contents/tab_contents.h"
43 #include "chrome/browser/ui/tabs/tab_strip_model.h" 44 #include "chrome/browser/ui/tabs/tab_strip_model.h"
(...skipping 30 matching lines...) Expand all
74 using content::Referrer; 75 using content::Referrer;
75 using content::SSLStatus; 76 using content::SSLStatus;
76 using content::UserMetricsAction; 77 using content::UserMetricsAction;
77 using content::WebContents; 78 using content::WebContents;
78 79
79 namespace chrome { 80 namespace chrome {
80 namespace { 81 namespace {
81 82
82 WebContents* GetOrCloneTabForDisposition(Browser* browser, 83 WebContents* GetOrCloneTabForDisposition(Browser* browser,
83 WindowOpenDisposition disposition) { 84 WindowOpenDisposition disposition) {
84 TabContents* current_tab = browser->GetActiveTabContents(); 85 TabContents* current_tab = chrome::GetActiveTabContents(browser);
85 switch (disposition) { 86 switch (disposition) {
86 case NEW_FOREGROUND_TAB: 87 case NEW_FOREGROUND_TAB:
87 case NEW_BACKGROUND_TAB: { 88 case NEW_BACKGROUND_TAB: {
88 current_tab = current_tab->Clone(); 89 current_tab = current_tab->Clone();
89 browser->tab_strip_model()->AddTabContents( 90 browser->tab_strip_model()->AddTabContents(
90 current_tab, -1, content::PAGE_TRANSITION_LINK, 91 current_tab, -1, content::PAGE_TRANSITION_LINK,
91 disposition == NEW_FOREGROUND_TAB ? TabStripModel::ADD_ACTIVE : 92 disposition == NEW_FOREGROUND_TAB ? TabStripModel::ADD_ACTIVE :
92 TabStripModel::ADD_NONE); 93 TabStripModel::ADD_NONE);
93 break; 94 break;
94 } 95 }
95 case NEW_WINDOW: { 96 case NEW_WINDOW: {
96 current_tab = current_tab->Clone(); 97 current_tab = current_tab->Clone();
97 Browser* b = Browser::Create(browser->profile()); 98 Browser* b = Browser::Create(browser->profile());
98 b->tab_strip_model()->AddTabContents( 99 b->tab_strip_model()->AddTabContents(
99 current_tab, -1, content::PAGE_TRANSITION_LINK, 100 current_tab, -1, content::PAGE_TRANSITION_LINK,
100 TabStripModel::ADD_ACTIVE); 101 TabStripModel::ADD_ACTIVE);
101 b->window()->Show(); 102 b->window()->Show();
102 break; 103 break;
103 } 104 }
104 default: 105 default:
105 break; 106 break;
106 } 107 }
107 return current_tab->web_contents(); 108 return current_tab->web_contents();
108 } 109 }
109 110
110 void ReloadInternal(Browser* browser, 111 void ReloadInternal(Browser* browser,
111 WindowOpenDisposition disposition, 112 WindowOpenDisposition disposition,
112 bool ignore_cache) { 113 bool ignore_cache) {
113 // If we are showing an interstitial, treat this as an OpenURL. 114 // If we are showing an interstitial, treat this as an OpenURL.
114 WebContents* current_tab = browser->GetActiveWebContents(); 115 WebContents* current_tab = chrome::GetActiveWebContents(browser);
115 if (current_tab && current_tab->ShowingInterstitialPage()) { 116 if (current_tab && current_tab->ShowingInterstitialPage()) {
116 NavigationEntry* entry = current_tab->GetController().GetActiveEntry(); 117 NavigationEntry* entry = current_tab->GetController().GetActiveEntry();
117 DCHECK(entry); // Should exist if interstitial is showing. 118 DCHECK(entry); // Should exist if interstitial is showing.
118 browser->OpenURL(OpenURLParams( 119 browser->OpenURL(OpenURLParams(
119 entry->GetURL(), Referrer(), disposition, 120 entry->GetURL(), Referrer(), disposition,
120 content::PAGE_TRANSITION_RELOAD, false)); 121 content::PAGE_TRANSITION_RELOAD, false));
121 return; 122 return;
122 } 123 }
123 124
124 // As this is caused by a user action, give the focus to the page. 125 // As this is caused by a user action, give the focus to the page.
125 // 126 //
126 // Also notify RenderViewHostDelegate of the user gesture; this is 127 // Also notify RenderViewHostDelegate of the user gesture; this is
127 // normally done in Browser::Navigate, but a reload bypasses Navigate. 128 // normally done in Browser::Navigate, but a reload bypasses Navigate.
128 WebContents* web_contents = GetOrCloneTabForDisposition(browser, disposition); 129 WebContents* web_contents = GetOrCloneTabForDisposition(browser, disposition);
129 web_contents->UserGestureDone(); 130 web_contents->UserGestureDone();
130 if (!web_contents->FocusLocationBarByDefault()) 131 if (!web_contents->FocusLocationBarByDefault())
131 web_contents->Focus(); 132 web_contents->Focus();
132 if (ignore_cache) 133 if (ignore_cache)
133 web_contents->GetController().ReloadIgnoringCache(true); 134 web_contents->GetController().ReloadIgnoringCache(true);
134 else 135 else
135 web_contents->GetController().Reload(true); 136 web_contents->GetController().Reload(true);
136 } 137 }
137 138
138 bool HasConstrainedWindow(const Browser* browser) { 139 bool HasConstrainedWindow(const Browser* browser) {
139 TabContents* tab_contents = browser->GetActiveTabContents(); 140 TabContents* tab_contents = GetActiveTabContents(browser);
140 return tab_contents && tab_contents->constrained_window_tab_helper()-> 141 return tab_contents && tab_contents->constrained_window_tab_helper()->
141 constrained_window_count(); 142 constrained_window_count();
142 } 143 }
143 144
144 bool PrintPreviewShowing(const Browser* browser) { 145 bool PrintPreviewShowing(const Browser* browser) {
145 TabContents* contents = browser->GetActiveTabContents(); 146 TabContents* contents = GetActiveTabContents(browser);
146 printing::PrintPreviewTabController* controller = 147 printing::PrintPreviewTabController* controller =
147 printing::PrintPreviewTabController::GetInstance(); 148 printing::PrintPreviewTabController::GetInstance();
148 return controller && (controller->GetPrintPreviewForTab(contents) || 149 return controller && (controller->GetPrintPreviewForTab(contents) ||
149 controller->is_creating_print_preview_tab()); 150 controller->is_creating_print_preview_tab());
150 } 151 }
151 152
152 } // namespace 153 } // namespace
153 154
154 bool IsCommandEnabled(Browser* browser, int command) { 155 bool IsCommandEnabled(Browser* browser, int command) {
155 return browser->command_controller()->command_updater()->IsCommandEnabled( 156 return browser->command_controller()->command_updater()->IsCommandEnabled(
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 188
188 void RemoveCommandObserver(Browser* browser, 189 void RemoveCommandObserver(Browser* browser,
189 int command, 190 int command,
190 CommandObserver* observer) { 191 CommandObserver* observer) {
191 browser->command_controller()->command_updater()->RemoveCommandObserver( 192 browser->command_controller()->command_updater()->RemoveCommandObserver(
192 command, observer); 193 command, observer);
193 } 194 }
194 195
195 int GetContentRestrictions(const Browser* browser) { 196 int GetContentRestrictions(const Browser* browser) {
196 int content_restrictions = 0; 197 int content_restrictions = 0;
197 WebContents* current_tab = browser->GetActiveWebContents(); 198 WebContents* current_tab = GetActiveWebContents(browser);
198 if (current_tab) { 199 if (current_tab) {
199 content_restrictions = current_tab->GetContentRestrictions(); 200 content_restrictions = current_tab->GetContentRestrictions();
200 NavigationEntry* active_entry = 201 NavigationEntry* active_entry =
201 current_tab->GetController().GetActiveEntry(); 202 current_tab->GetController().GetActiveEntry();
202 // See comment in UpdateCommandsForTabState about why we call url(). 203 // See comment in UpdateCommandsForTabState about why we call url().
203 if (!download_util::IsSavableURL( 204 if (!download_util::IsSavableURL(
204 active_entry ? active_entry->GetURL() : GURL()) || 205 active_entry ? active_entry->GetURL() : GURL()) ||
205 current_tab->ShowingInterstitialPage()) 206 current_tab->ShowingInterstitialPage())
206 content_restrictions |= content::CONTENT_RESTRICTION_SAVE; 207 content_restrictions |= content::CONTENT_RESTRICTION_SAVE;
207 if (current_tab->ShowingInterstitialPage()) 208 if (current_tab->ShowingInterstitialPage())
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 250
250 void OpenWindowWithRestoredTabs(Profile* profile) { 251 void OpenWindowWithRestoredTabs(Profile* profile) {
251 TabRestoreService* service = TabRestoreServiceFactory::GetForProfile(profile); 252 TabRestoreService* service = TabRestoreServiceFactory::GetForProfile(profile);
252 if (service) 253 if (service)
253 service->RestoreMostRecentEntry(NULL); 254 service->RestoreMostRecentEntry(NULL);
254 } 255 }
255 256
256 void OpenURLOffTheRecord(Profile* profile, const GURL& url) { 257 void OpenURLOffTheRecord(Profile* profile, const GURL& url) {
257 Browser* browser = browser::FindOrCreateTabbedBrowser( 258 Browser* browser = browser::FindOrCreateTabbedBrowser(
258 profile->GetOffTheRecordProfile()); 259 profile->GetOffTheRecordProfile());
259 browser->AddSelectedTabWithURL(url, content::PAGE_TRANSITION_LINK); 260 AddSelectedTabWithURL(browser, url, content::PAGE_TRANSITION_LINK);
260 browser->window()->Show(); 261 browser->window()->Show();
261 } 262 }
262 263
263 bool CanGoBack(const Browser* browser) { 264 bool CanGoBack(const Browser* browser) {
264 return browser->GetActiveWebContents()->GetController().CanGoBack(); 265 return GetActiveWebContents(browser)->GetController().CanGoBack();
265 } 266 }
266 267
267 void GoBack(Browser* browser, WindowOpenDisposition disposition) { 268 void GoBack(Browser* browser, WindowOpenDisposition disposition) {
268 content::RecordAction(UserMetricsAction("Back")); 269 content::RecordAction(UserMetricsAction("Back"));
269 270
270 TabContents* current_tab = browser->GetActiveTabContents(); 271 TabContents* current_tab = GetActiveTabContents(browser);
271 if (CanGoBack(browser)) { 272 if (CanGoBack(browser)) {
272 WebContents* new_tab = GetOrCloneTabForDisposition(browser, disposition); 273 WebContents* new_tab = GetOrCloneTabForDisposition(browser, disposition);
273 // If we are on an interstitial page and clone the tab, it won't be copied 274 // If we are on an interstitial page and clone the tab, it won't be copied
274 // to the new tab, so we don't need to go back. 275 // to the new tab, so we don't need to go back.
275 if (current_tab->web_contents()->ShowingInterstitialPage() && 276 if (current_tab->web_contents()->ShowingInterstitialPage() &&
276 (new_tab != current_tab->web_contents())) 277 (new_tab != current_tab->web_contents()))
277 return; 278 return;
278 new_tab->GetController().GoBack(); 279 new_tab->GetController().GoBack();
279 } 280 }
280 } 281 }
281 282
282 bool CanGoForward(const Browser* browser) { 283 bool CanGoForward(const Browser* browser) {
283 return browser->GetActiveWebContents()->GetController().CanGoForward(); 284 return GetActiveWebContents(browser)->GetController().CanGoForward();
284 } 285 }
285 286
286 void GoForward(Browser* browser, WindowOpenDisposition disposition) { 287 void GoForward(Browser* browser, WindowOpenDisposition disposition) {
287 content::RecordAction(UserMetricsAction("Forward")); 288 content::RecordAction(UserMetricsAction("Forward"));
288 if (CanGoForward(browser)) { 289 if (CanGoForward(browser)) {
289 GetOrCloneTabForDisposition(browser, disposition)-> 290 GetOrCloneTabForDisposition(browser, disposition)->
290 GetController().GoForward(); 291 GetController().GoForward();
291 } 292 }
292 } 293 }
293 294
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 355
355 DCHECK(browser->profile()->GetExtensionService()); 356 DCHECK(browser->profile()->GetExtensionService());
356 if (browser->profile()->GetExtensionService()->IsInstalledApp(url)) { 357 if (browser->profile()->GetExtensionService()->IsInstalledApp(url)) {
357 AppLauncherHandler::RecordAppLaunchType( 358 AppLauncherHandler::RecordAppLaunchType(
358 extension_misc::APP_LAUNCH_OMNIBOX_LOCATION); 359 extension_misc::APP_LAUNCH_OMNIBOX_LOCATION);
359 } 360 }
360 } 361 }
361 362
362 void Stop(Browser* browser) { 363 void Stop(Browser* browser) {
363 content::RecordAction(UserMetricsAction("Stop")); 364 content::RecordAction(UserMetricsAction("Stop"));
364 browser->GetActiveWebContents()->Stop(); 365 GetActiveWebContents(browser)->Stop();
365 } 366 }
366 367
367 #if !defined(OS_WIN) 368 #if !defined(OS_WIN)
368 void NewWindow(Browser* browser) { 369 void NewWindow(Browser* browser) {
369 NewEmptyWindow(browser->profile()->GetOriginalProfile()); 370 NewEmptyWindow(browser->profile()->GetOriginalProfile());
370 } 371 }
371 372
372 void NewIncognitoWindow(Browser* browser) { 373 void NewIncognitoWindow(Browser* browser) {
373 NewEmptyWindow(browser->profile()->GetOffTheRecordProfile()); 374 NewEmptyWindow(browser->profile()->GetOffTheRecordProfile());
374 } 375 }
375 #endif // OS_WIN 376 #endif // OS_WIN
376 377
377 void CloseWindow(Browser* browser) { 378 void CloseWindow(Browser* browser) {
378 content::RecordAction(UserMetricsAction("CloseWindow")); 379 content::RecordAction(UserMetricsAction("CloseWindow"));
379 browser->window()->Close(); 380 browser->window()->Close();
380 } 381 }
381 382
382 void NewTab(Browser* browser) { 383 void NewTab(Browser* browser) {
383 content::RecordAction(UserMetricsAction("NewTab")); 384 content::RecordAction(UserMetricsAction("NewTab"));
384 // TODO(asvitkine): This is invoked programmatically from several places. 385 // TODO(asvitkine): This is invoked programmatically from several places.
385 // Audit the code and change it so that the histogram only gets collected for 386 // Audit the code and change it so that the histogram only gets collected for
386 // user-initiated commands. 387 // user-initiated commands.
387 UMA_HISTOGRAM_ENUMERATION("Tab.NewTab", TabStripModel::NEW_TAB_COMMAND, 388 UMA_HISTOGRAM_ENUMERATION("Tab.NewTab", TabStripModel::NEW_TAB_COMMAND,
388 TabStripModel::NEW_TAB_ENUM_COUNT); 389 TabStripModel::NEW_TAB_ENUM_COUNT);
389 390
390 if (browser->is_type_tabbed()) { 391 if (browser->is_type_tabbed()) {
391 browser->AddBlankTab(true); 392 browser->AddBlankTab(true);
392 browser->GetActiveWebContents()->GetView()->RestoreFocus(); 393 GetActiveWebContents(browser)->GetView()->RestoreFocus();
393 } else { 394 } else {
394 Browser* b = browser::FindOrCreateTabbedBrowser(browser->profile()); 395 Browser* b = browser::FindOrCreateTabbedBrowser(browser->profile());
395 b->AddBlankTab(true); 396 b->AddBlankTab(true);
396 b->window()->Show(); 397 b->window()->Show();
397 // The call to AddBlankTab above did not set the focus to the tab as its 398 // The call to AddBlankTab above did not set the focus to the tab as its
398 // window was not active, so we have to do it explicitly. 399 // window was not active, so we have to do it explicitly.
399 // See http://crbug.com/6380. 400 // See http://crbug.com/6380.
400 b->GetActiveWebContents()->GetView()->RestoreFocus(); 401 chrome::GetActiveWebContents(b)->GetView()->RestoreFocus();
401 } 402 }
402 } 403 }
403 404
404 void CloseTab(Browser* browser) { 405 void CloseTab(Browser* browser) {
405 content::RecordAction(UserMetricsAction("CloseTab_Accelerator")); 406 content::RecordAction(UserMetricsAction("CloseTab_Accelerator"));
406 browser->tab_strip_model()->CloseSelectedTabs(); 407 browser->tab_strip_model()->CloseSelectedTabs();
407 } 408 }
408 409
409 void RestoreTab(Browser* browser) { 410 void RestoreTab(Browser* browser) {
410 content::RecordAction(UserMetricsAction("RestoreTab")); 411 content::RecordAction(UserMetricsAction("RestoreTab"));
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 } 451 }
451 452
452 void MoveTabPrevious(Browser* browser) { 453 void MoveTabPrevious(Browser* browser) {
453 content::RecordAction(UserMetricsAction("MoveTabPrevious")); 454 content::RecordAction(UserMetricsAction("MoveTabPrevious"));
454 browser->tab_strip_model()->MoveTabPrevious(); 455 browser->tab_strip_model()->MoveTabPrevious();
455 } 456 }
456 457
457 void SelectNumberedTab(Browser* browser, int index) { 458 void SelectNumberedTab(Browser* browser, int index) {
458 if (index < browser->tab_count()) { 459 if (index < browser->tab_count()) {
459 content::RecordAction(UserMetricsAction("SelectNumberedTab")); 460 content::RecordAction(UserMetricsAction("SelectNumberedTab"));
460 browser->ActivateTabAt(index, true); 461 ActivateTabAt(browser, index, true);
461 } 462 }
462 } 463 }
463 464
464 void SelectLastTab(Browser* browser) { 465 void SelectLastTab(Browser* browser) {
465 content::RecordAction(UserMetricsAction("SelectLastTab")); 466 content::RecordAction(UserMetricsAction("SelectLastTab"));
466 browser->tab_strip_model()->SelectLastTab(); 467 browser->tab_strip_model()->SelectLastTab();
467 } 468 }
468 469
469 void DuplicateTab(Browser* browser) { 470 void DuplicateTab(Browser* browser) {
470 content::RecordAction(UserMetricsAction("Duplicate")); 471 content::RecordAction(UserMetricsAction("Duplicate"));
471 browser->DuplicateContentsAt(browser->active_index()); 472 browser->DuplicateContentsAt(browser->active_index());
472 } 473 }
473 474
474 bool CanDuplicateTab(const Browser* browser) { 475 bool CanDuplicateTab(const Browser* browser) {
475 WebContents* contents = browser->GetActiveWebContents(); 476 WebContents* contents = GetActiveWebContents(browser);
476 return contents && contents->GetController().GetLastCommittedEntry(); 477 return contents && contents->GetController().GetLastCommittedEntry();
477 } 478 }
478 479
479 void WriteCurrentURLToClipboard(Browser* browser) { 480 void WriteCurrentURLToClipboard(Browser* browser) {
480 // TODO(ericu): There isn't currently a metric for this. Should there be? 481 // TODO(ericu): There isn't currently a metric for this. Should there be?
481 // We don't appear to track the action when it comes from the 482 // We don't appear to track the action when it comes from the
482 // RenderContextViewMenu. 483 // RenderContextViewMenu.
483 484
484 WebContents* contents = browser->GetActiveWebContents(); 485 WebContents* contents = GetActiveWebContents(browser);
485 if (!browser->toolbar_model()->ShouldDisplayURL()) 486 if (!browser->toolbar_model()->ShouldDisplayURL())
486 return; 487 return;
487 488
488 chrome_common_net::WriteURLToClipboard( 489 chrome_common_net::WriteURLToClipboard(
489 contents->GetURL(), 490 contents->GetURL(),
490 browser->profile()->GetPrefs()->GetString(prefs::kAcceptLanguages), 491 browser->profile()->GetPrefs()->GetString(prefs::kAcceptLanguages),
491 g_browser_process->clipboard()); 492 g_browser_process->clipboard());
492 } 493 }
493 494
494 void ConvertPopupToTabbedBrowser(Browser* browser) { 495 void ConvertPopupToTabbedBrowser(Browser* browser) {
(...skipping 12 matching lines...) Expand all
507 508
508 void BookmarkCurrentPage(Browser* browser) { 509 void BookmarkCurrentPage(Browser* browser) {
509 content::RecordAction(UserMetricsAction("Star")); 510 content::RecordAction(UserMetricsAction("Star"));
510 511
511 BookmarkModel* model = browser->profile()->GetBookmarkModel(); 512 BookmarkModel* model = browser->profile()->GetBookmarkModel();
512 if (!model || !model->IsLoaded()) 513 if (!model || !model->IsLoaded())
513 return; // Ignore requests until bookmarks are loaded. 514 return; // Ignore requests until bookmarks are loaded.
514 515
515 GURL url; 516 GURL url;
516 string16 title; 517 string16 title;
517 TabContents* tab = browser->GetActiveTabContents(); 518 TabContents* tab = GetActiveTabContents(browser);
518 bookmark_utils::GetURLAndTitleToBookmark(tab->web_contents(), &url, &title); 519 bookmark_utils::GetURLAndTitleToBookmark(tab->web_contents(), &url, &title);
519 bool was_bookmarked = model->IsBookmarked(url); 520 bool was_bookmarked = model->IsBookmarked(url);
520 if (!was_bookmarked && browser->profile()->IsOffTheRecord()) { 521 if (!was_bookmarked && browser->profile()->IsOffTheRecord()) {
521 // If we're incognito the favicon may not have been saved. Save it now 522 // If we're incognito the favicon may not have been saved. Save it now
522 // so that bookmarks have an icon for the page. 523 // so that bookmarks have an icon for the page.
523 tab->favicon_tab_helper()->SaveFavicon(); 524 tab->favicon_tab_helper()->SaveFavicon();
524 } 525 }
525 bookmark_utils::AddIfNotBookmarked(model, url, title); 526 bookmark_utils::AddIfNotBookmarked(model, url, title);
526 // Make sure the model actually added a bookmark before showing the star. A 527 // Make sure the model actually added a bookmark before showing the star. A
527 // bookmark isn't created if the url is invalid. 528 // bookmark isn't created if the url is invalid.
(...skipping 20 matching lines...) Expand all
548 return browser->tab_count() > 1 && CanBookmarkCurrentPage(browser); 549 return browser->tab_count() > 1 && CanBookmarkCurrentPage(browser);
549 } 550 }
550 551
551 #if !defined(OS_WIN) 552 #if !defined(OS_WIN)
552 void PinCurrentPageToStartScreen(Browser* browser) { 553 void PinCurrentPageToStartScreen(Browser* browser) {
553 } 554 }
554 #endif 555 #endif
555 556
556 void SavePage(Browser* browser) { 557 void SavePage(Browser* browser) {
557 content::RecordAction(UserMetricsAction("SavePage")); 558 content::RecordAction(UserMetricsAction("SavePage"));
558 WebContents* current_tab = browser->GetActiveWebContents(); 559 WebContents* current_tab = GetActiveWebContents(browser);
559 if (current_tab && current_tab->GetContentsMimeType() == "application/pdf") 560 if (current_tab && current_tab->GetContentsMimeType() == "application/pdf")
560 content::RecordAction(UserMetricsAction("PDF.SavePage")); 561 content::RecordAction(UserMetricsAction("PDF.SavePage"));
561 current_tab->OnSavePage(); 562 current_tab->OnSavePage();
562 } 563 }
563 564
564 bool CanSavePage(const Browser* browser) { 565 bool CanSavePage(const Browser* browser) {
565 // LocalState can be NULL in tests. 566 // LocalState can be NULL in tests.
566 if (g_browser_process->local_state() && 567 if (g_browser_process->local_state() &&
567 !g_browser_process->local_state()->GetBoolean( 568 !g_browser_process->local_state()->GetBoolean(
568 prefs::kAllowFileSelectionDialogs)) { 569 prefs::kAllowFileSelectionDialogs)) {
(...skipping 28 matching lines...) Expand all
597 void ShowChromeToMobileBubble(Browser* browser) { 598 void ShowChromeToMobileBubble(Browser* browser) {
598 // Only show the bubble if the window is active, otherwise we may get into 599 // Only show the bubble if the window is active, otherwise we may get into
599 // weird situations where the bubble is deleted as soon as it is shown. 600 // weird situations where the bubble is deleted as soon as it is shown.
600 if (browser->window()->IsActive()) 601 if (browser->window()->IsActive())
601 browser->window()->ShowChromeToMobileBubble(); 602 browser->window()->ShowChromeToMobileBubble();
602 } 603 }
603 604
604 void Print(Browser* browser) { 605 void Print(Browser* browser) {
605 if (g_browser_process->local_state()->GetBoolean( 606 if (g_browser_process->local_state()->GetBoolean(
606 prefs::kPrintPreviewDisabled)) { 607 prefs::kPrintPreviewDisabled)) {
607 browser->GetActiveTabContents()->print_view_manager()->PrintNow(); 608 GetActiveTabContents(browser)->print_view_manager()->PrintNow();
608 } else { 609 } else {
609 browser->GetActiveTabContents()->print_view_manager()->PrintPreviewNow(); 610 GetActiveTabContents(browser)->print_view_manager()->
611 PrintPreviewNow();
610 } 612 }
611 } 613 }
612 614
613 bool CanPrint(const Browser* browser) { 615 bool CanPrint(const Browser* browser) {
614 // LocalState can be NULL in tests. 616 // LocalState can be NULL in tests.
615 if (g_browser_process->local_state() && 617 if (g_browser_process->local_state() &&
616 !g_browser_process->local_state()->GetBoolean(prefs::kPrintingEnabled)) { 618 !g_browser_process->local_state()->GetBoolean(prefs::kPrintingEnabled)) {
617 return false; 619 return false;
618 } 620 }
619 621
620 // Do not print when a constrained window is showing. It's confusing. 622 // Do not print when a constrained window is showing. It's confusing.
621 return !(HasConstrainedWindow(browser) || 623 return !(HasConstrainedWindow(browser) ||
622 GetContentRestrictions(browser) & content::CONTENT_RESTRICTION_PRINT); 624 GetContentRestrictions(browser) & content::CONTENT_RESTRICTION_PRINT);
623 } 625 }
624 626
625 void AdvancedPrint(Browser* browser) { 627 void AdvancedPrint(Browser* browser) {
626 browser->GetActiveTabContents()->print_view_manager()->AdvancedPrintNow(); 628 GetActiveTabContents(browser)->print_view_manager()->
629 AdvancedPrintNow();
627 } 630 }
628 631
629 bool CanAdvancedPrint(const Browser* browser) { 632 bool CanAdvancedPrint(const Browser* browser) {
630 // LocalState can be NULL in tests. 633 // LocalState can be NULL in tests.
631 if (g_browser_process->local_state() && 634 if (g_browser_process->local_state() &&
632 !g_browser_process->local_state()->GetBoolean(prefs::kPrintingEnabled)) { 635 !g_browser_process->local_state()->GetBoolean(prefs::kPrintingEnabled)) {
633 return false; 636 return false;
634 } 637 }
635 638
636 // It is always possible to advanced print when print preview is visible. 639 // It is always possible to advanced print when print preview is visible.
637 return PrintPreviewShowing(browser) || CanPrint(browser); 640 return PrintPreviewShowing(browser) || CanPrint(browser);
638 } 641 }
639 642
640 void PrintToDestination(Browser* browser) { 643 void PrintToDestination(Browser* browser) {
641 browser->GetActiveTabContents()->print_view_manager()->PrintToDestination(); 644 GetActiveTabContents(browser)->print_view_manager()->PrintToDestination();
642 } 645 }
643 646
644 void EmailPageLocation(Browser* browser) { 647 void EmailPageLocation(Browser* browser) {
645 content::RecordAction(UserMetricsAction("EmailPageLocation")); 648 content::RecordAction(UserMetricsAction("EmailPageLocation"));
646 WebContents* wc = browser->GetActiveWebContents(); 649 WebContents* wc = GetActiveWebContents(browser);
647 DCHECK(wc); 650 DCHECK(wc);
648 651
649 std::string title = net::EscapeQueryParamValue( 652 std::string title = net::EscapeQueryParamValue(
650 UTF16ToUTF8(wc->GetTitle()), false); 653 UTF16ToUTF8(wc->GetTitle()), false);
651 std::string page_url = net::EscapeQueryParamValue(wc->GetURL().spec(), false); 654 std::string page_url = net::EscapeQueryParamValue(wc->GetURL().spec(), false);
652 std::string mailto = std::string("mailto:?subject=Fwd:%20") + 655 std::string mailto = std::string("mailto:?subject=Fwd:%20") +
653 title + "&body=%0A%0A" + page_url; 656 title + "&body=%0A%0A" + page_url;
654 platform_util::OpenExternal(GURL(mailto)); 657 platform_util::OpenExternal(GURL(mailto));
655 } 658 }
656 659
657 bool CanEmailPageLocation(const Browser* browser) { 660 bool CanEmailPageLocation(const Browser* browser) {
658 return browser->toolbar_model()->ShouldDisplayURL() && 661 return browser->toolbar_model()->ShouldDisplayURL() &&
659 browser->GetActiveWebContents()->GetURL().is_valid(); 662 GetActiveWebContents(browser)->GetURL().is_valid();
660 } 663 }
661 664
662 void Cut(Browser* browser) { 665 void Cut(Browser* browser) {
663 content::RecordAction(UserMetricsAction("Cut")); 666 content::RecordAction(UserMetricsAction("Cut"));
664 browser->window()->Cut(); 667 browser->window()->Cut();
665 } 668 }
666 669
667 void Copy(Browser* browser) { 670 void Copy(Browser* browser) {
668 content::RecordAction(UserMetricsAction("Copy")); 671 content::RecordAction(UserMetricsAction("Copy"));
669 browser->window()->Copy(); 672 browser->window()->Copy();
(...skipping 20 matching lines...) Expand all
690 } 693 }
691 694
692 void FindInPage(Browser* browser, bool find_next, bool forward_direction) { 695 void FindInPage(Browser* browser, bool find_next, bool forward_direction) {
693 ShowFindBar(browser); 696 ShowFindBar(browser);
694 if (find_next) { 697 if (find_next) {
695 string16 find_text; 698 string16 find_text;
696 #if defined(OS_MACOSX) 699 #if defined(OS_MACOSX)
697 // We always want to search for the contents of the find pasteboard on OS X. 700 // We always want to search for the contents of the find pasteboard on OS X.
698 find_text = GetFindPboardText(); 701 find_text = GetFindPboardText();
699 #endif 702 #endif
700 browser->GetActiveTabContents()-> 703 GetActiveTabContents(browser)->
701 find_tab_helper()->StartFinding(find_text, 704 find_tab_helper()->StartFinding(find_text,
702 forward_direction, 705 forward_direction,
703 false); // Not case sensitive. 706 false); // Not case sensitive.
704 } 707 }
705 } 708 }
706 709
707 void Zoom(Browser* browser, content::PageZoom zoom) { 710 void Zoom(Browser* browser, content::PageZoom zoom) {
708 if (browser->is_devtools()) 711 if (browser->is_devtools())
709 return; 712 return;
710 713
711 content::RenderViewHost* host = 714 content::RenderViewHost* host =
712 browser->GetActiveWebContents()->GetRenderViewHost(); 715 GetActiveWebContents(browser)->GetRenderViewHost();
713 if (zoom == content::PAGE_ZOOM_RESET) { 716 if (zoom == content::PAGE_ZOOM_RESET) {
714 host->SetZoomLevel(0); 717 host->SetZoomLevel(0);
715 content::RecordAction(UserMetricsAction("ZoomNormal")); 718 content::RecordAction(UserMetricsAction("ZoomNormal"));
716 return; 719 return;
717 } 720 }
718 721
719 double current_zoom_level = browser->GetActiveWebContents()->GetZoomLevel(); 722 double current_zoom_level = GetActiveWebContents(browser)->GetZoomLevel();
720 double default_zoom_level = 723 double default_zoom_level =
721 browser->profile()->GetPrefs()->GetDouble(prefs::kDefaultZoomLevel); 724 browser->profile()->GetPrefs()->GetDouble(prefs::kDefaultZoomLevel);
722 725
723 // Generate a vector of zoom levels from an array of known presets along with 726 // Generate a vector of zoom levels from an array of known presets along with
724 // the default level added if necessary. 727 // the default level added if necessary.
725 std::vector<double> zoom_levels = 728 std::vector<double> zoom_levels =
726 chrome_page_zoom::PresetZoomLevels(default_zoom_level); 729 chrome_page_zoom::PresetZoomLevels(default_zoom_level);
727 730
728 if (zoom == content::PAGE_ZOOM_OUT) { 731 if (zoom == content::PAGE_ZOOM_OUT) {
729 // Iterate through the zoom levels in reverse order to find the next 732 // Iterate through the zoom levels in reverse order to find the next
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
794 browser->window()->RotatePaneFocus(false); 797 browser->window()->RotatePaneFocus(false);
795 } 798 }
796 799
797 void ToggleDevToolsWindow(Browser* browser, DevToolsToggleAction action) { 800 void ToggleDevToolsWindow(Browser* browser, DevToolsToggleAction action) {
798 if (action == DEVTOOLS_TOGGLE_ACTION_SHOW_CONSOLE) 801 if (action == DEVTOOLS_TOGGLE_ACTION_SHOW_CONSOLE)
799 content::RecordAction(UserMetricsAction("DevTools_ToggleConsole")); 802 content::RecordAction(UserMetricsAction("DevTools_ToggleConsole"));
800 else 803 else
801 content::RecordAction(UserMetricsAction("DevTools_ToggleWindow")); 804 content::RecordAction(UserMetricsAction("DevTools_ToggleWindow"));
802 805
803 DevToolsWindow::ToggleDevToolsWindow( 806 DevToolsWindow::ToggleDevToolsWindow(
804 browser->GetActiveWebContents()->GetRenderViewHost(), 807 GetActiveWebContents(browser)->GetRenderViewHost(),
805 action); 808 action);
806 } 809 }
807 810
808 bool CanOpenTaskManager() { 811 bool CanOpenTaskManager() {
809 #if defined(OS_WIN) 812 #if defined(OS_WIN)
810 // In metro we can't display the task manager, as it is a native window. 813 // In metro we can't display the task manager, as it is a native window.
811 return !base::win::IsMetroProcess(); 814 return !base::win::IsMetroProcess();
812 #else 815 #else
813 return true; 816 return true;
814 #endif 817 #endif
(...skipping 25 matching lines...) Expand all
840 void ShowAvatarMenu(Browser* browser) { 843 void ShowAvatarMenu(Browser* browser) {
841 browser->window()->ShowAvatarBubbleFromAvatarButton(); 844 browser->window()->ShowAvatarBubbleFromAvatarButton();
842 } 845 }
843 846
844 void OpenUpdateChromeDialog(Browser* browser) { 847 void OpenUpdateChromeDialog(Browser* browser) {
845 content::RecordAction(UserMetricsAction("UpdateChrome")); 848 content::RecordAction(UserMetricsAction("UpdateChrome"));
846 browser->window()->ShowUpdateChromeDialog(); 849 browser->window()->ShowUpdateChromeDialog();
847 } 850 }
848 851
849 void ToggleSpeechInput(Browser* browser) { 852 void ToggleSpeechInput(Browser* browser) {
850 browser->GetActiveWebContents()->GetRenderViewHost()->ToggleSpeechInput(); 853 GetActiveWebContents(browser)->GetRenderViewHost()->ToggleSpeechInput();
851 } 854 }
852 855
853 void ViewSource(Browser* browser, TabContents* contents) { 856 void ViewSource(Browser* browser, TabContents* contents) {
854 DCHECK(contents); 857 DCHECK(contents);
855 858
856 NavigationEntry* active_entry = 859 NavigationEntry* active_entry =
857 contents->web_contents()->GetController().GetActiveEntry(); 860 contents->web_contents()->GetController().GetActiveEntry();
858 if (!active_entry) 861 if (!active_entry)
859 return; 862 return;
860 863
861 ViewSource(browser, contents, active_entry->GetURL(), 864 ViewSource(browser, contents, active_entry->GetURL(),
862 active_entry->GetContentState()); 865 active_entry->GetContentState());
863 } 866 }
864 867
865 void ViewSource(Browser* browser, 868 void ViewSource(Browser* browser,
866 TabContents* contents, 869 TabContents* contents,
867 const GURL& url, 870 const GURL& url,
868 const std::string& content_state) { 871 const std::string& content_state) {
869 content::RecordAction(UserMetricsAction("ViewSource")); 872 content::RecordAction(UserMetricsAction("ViewSource"));
870 DCHECK(contents); 873 DCHECK(contents);
871 874
872 TabContents* view_source_contents = contents->Clone(); 875 TabContents* view_source_contents = contents->Clone();
873 view_source_contents->web_contents()->GetController().PruneAllButActive(); 876 view_source_contents->web_contents()->GetController().PruneAllButActive();
874 NavigationEntry* active_entry = 877 NavigationEntry* active_entry =
875 view_source_contents->web_contents()->GetController().GetActiveEntry(); 878 view_source_contents->web_contents()->GetController().GetActiveEntry();
876 if (!active_entry) 879 if (!active_entry)
877 return; 880 return;
878 881
879 GURL view_source_url = GURL(chrome::kViewSourceScheme + std::string(":") + 882 GURL view_source_url = GURL(kViewSourceScheme + std::string(":") +
880 url.spec()); 883 url.spec());
881 active_entry->SetVirtualURL(view_source_url); 884 active_entry->SetVirtualURL(view_source_url);
882 885
883 // Do not restore scroller position. 886 // Do not restore scroller position.
884 active_entry->SetContentState( 887 active_entry->SetContentState(
885 webkit_glue::RemoveScrollOffsetFromHistoryState(content_state)); 888 webkit_glue::RemoveScrollOffsetFromHistoryState(content_state));
886 889
887 // Do not restore title, derive it from the url. 890 // Do not restore title, derive it from the url.
888 active_entry->SetTitle(string16()); 891 active_entry->SetTitle(string16());
889 892
(...skipping 15 matching lines...) Expand all
905 // been given an offset by the OS, so we shouldn't copy the old bounds. 908 // been given an offset by the OS, so we shouldn't copy the old bounds.
906 BrowserWindow* new_window = b->window(); 909 BrowserWindow* new_window = b->window();
907 new_window->SetBounds(gfx::Rect(new_window->GetRestoredBounds().origin(), 910 new_window->SetBounds(gfx::Rect(new_window->GetRestoredBounds().origin(),
908 browser->window()->GetRestoredBounds().size())); 911 browser->window()->GetRestoredBounds().size()));
909 912
910 // We need to show the browser now. Otherwise ContainerWin assumes the 913 // We need to show the browser now. Otherwise ContainerWin assumes the
911 // WebContents is invisible and won't size it. 914 // WebContents is invisible and won't size it.
912 b->window()->Show(); 915 b->window()->Show();
913 916
914 // The page transition below is only for the purpose of inserting the tab. 917 // The page transition below is only for the purpose of inserting the tab.
915 b->AddTab(view_source_contents, content::PAGE_TRANSITION_LINK); 918 chrome::AddTab(b, view_source_contents, content::PAGE_TRANSITION_LINK);
916 } 919 }
917 920
918 SessionService* session_service = 921 SessionService* session_service =
919 SessionServiceFactory::GetForProfileIfExisting(browser->profile()); 922 SessionServiceFactory::GetForProfileIfExisting(browser->profile());
920 if (session_service) 923 if (session_service)
921 session_service->TabRestored(view_source_contents, false); 924 session_service->TabRestored(view_source_contents, false);
922 } 925 }
923 926
924 void ViewSelectedSource(Browser* browser) { 927 void ViewSelectedSource(Browser* browser) {
925 ViewSource(browser, browser->GetActiveTabContents()); 928 ViewSource(browser, chrome::GetActiveTabContents(browser));
926 } 929 }
927 930
928 bool CanViewSource(const Browser* browser) { 931 bool CanViewSource(const Browser* browser) {
929 return browser->GetActiveWebContents()->GetController().CanViewSource(); 932 return chrome::GetActiveWebContents(browser)->GetController().CanViewSource();
930 } 933 }
931 934
932 bool CanCreateApplicationShortcuts(const Browser* browser) { 935 bool CanCreateApplicationShortcuts(const Browser* browser) {
933 return web_app::IsValidUrl(browser->GetActiveWebContents()->GetURL()); 936 return web_app::IsValidUrl(chrome::GetActiveWebContents(browser)->GetURL());
934 } 937 }
935 938
936 void ConvertTabToAppWindow(Browser* browser, 939 void ConvertTabToAppWindow(Browser* browser,
937 content::WebContents* contents) { 940 content::WebContents* contents) {
938 const GURL& url = contents->GetController().GetActiveEntry()->GetURL(); 941 const GURL& url = contents->GetController().GetActiveEntry()->GetURL();
939 std::string app_name = web_app::GenerateApplicationNameFromURL(url); 942 std::string app_name = web_app::GenerateApplicationNameFromURL(url);
940 943
941 int index = browser->tab_strip_model()->GetIndexOfWebContents(contents); 944 int index = browser->tab_strip_model()->GetIndexOfWebContents(contents);
942 if (index >= 0) 945 if (index >= 0)
943 browser->tab_strip_model()->DetachTabContentsAt(index); 946 browser->tab_strip_model()->DetachTabContentsAt(index);
944 947
945 Browser* app_browser = Browser::CreateWithParams( 948 Browser* app_browser = Browser::CreateWithParams(
946 Browser::CreateParams::CreateForApp( 949 Browser::CreateParams::CreateForApp(
947 Browser::TYPE_POPUP, app_name, gfx::Rect(), browser->profile())); 950 Browser::TYPE_POPUP, app_name, gfx::Rect(), browser->profile()));
948 TabContents* tab_contents = TabContents::FromWebContents(contents); 951 TabContents* tab_contents = TabContents::FromWebContents(contents);
949 if (!tab_contents) 952 if (!tab_contents)
950 tab_contents = new TabContents(contents); 953 tab_contents = new TabContents(contents);
951 app_browser->tab_strip_model()->AppendTabContents(tab_contents, true); 954 app_browser->tab_strip_model()->AppendTabContents(tab_contents, true);
952 955
953 contents->GetMutableRendererPrefs()->can_accept_load_drops = false; 956 contents->GetMutableRendererPrefs()->can_accept_load_drops = false;
954 contents->GetRenderViewHost()->SyncRendererPrefs(); 957 contents->GetRenderViewHost()->SyncRendererPrefs();
955 app_browser->window()->Show(); 958 app_browser->window()->Show();
956 } 959 }
957 960
958 } // namespace chrome 961 } // namespace chrome
OLDNEW
« no previous file with comments | « chrome/browser/ui/browser_command_controller.cc ('k') | chrome/browser/ui/browser_content_setting_bubble_model_delegate.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698