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 "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_model.h" | 11 #include "chrome/browser/bookmarks/bookmark_model.h" |
11 #include "chrome/browser/bookmarks/bookmark_utils.h" | 12 #include "chrome/browser/bookmarks/bookmark_utils.h" |
12 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
13 #include "chrome/browser/chrome_page_zoom.h" | 14 #include "chrome/browser/chrome_page_zoom.h" |
14 #include "chrome/browser/debugger/devtools_window.h" | 15 #include "chrome/browser/debugger/devtools_window.h" |
| 16 #include "chrome/browser/download/download_util.h" |
15 #include "chrome/browser/extensions/extension_service.h" | 17 #include "chrome/browser/extensions/extension_service.h" |
16 #include "chrome/browser/favicon/favicon_tab_helper.h" | 18 #include "chrome/browser/favicon/favicon_tab_helper.h" |
17 #include "chrome/browser/lifetime/application_lifetime.h" | 19 #include "chrome/browser/lifetime/application_lifetime.h" |
18 #include "chrome/browser/platform_util.h" | 20 #include "chrome/browser/platform_util.h" |
19 #include "chrome/browser/prefs/incognito_mode_prefs.h" | 21 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
20 #include "chrome/browser/prefs/pref_service.h" | 22 #include "chrome/browser/prefs/pref_service.h" |
| 23 #include "chrome/browser/printing/print_preview_tab_controller.h" |
21 #include "chrome/browser/printing/print_view_manager.h" | 24 #include "chrome/browser/printing/print_view_manager.h" |
22 #include "chrome/browser/profiles/profile.h" | 25 #include "chrome/browser/profiles/profile.h" |
23 #include "chrome/browser/sessions/session_service_factory.h" | 26 #include "chrome/browser/sessions/session_service_factory.h" |
24 #include "chrome/browser/sessions/tab_restore_service_factory.h" | 27 #include "chrome/browser/sessions/tab_restore_service_factory.h" |
25 #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" |
26 #include "chrome/browser/ui/browser.h" | 30 #include "chrome/browser/ui/browser.h" |
| 31 #include "chrome/browser/ui/browser_command_controller.h" |
27 #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" |
28 #include "chrome/browser/ui/browser_window.h" | 34 #include "chrome/browser/ui/browser_window.h" |
| 35 #include "chrome/browser/ui/constrained_window_tab_helper.h" |
29 #include "chrome/browser/ui/find_bar/find_bar_controller.h" | 36 #include "chrome/browser/ui/find_bar/find_bar_controller.h" |
30 #include "chrome/browser/ui/find_bar/find_tab_helper.h" | 37 #include "chrome/browser/ui/find_bar/find_tab_helper.h" |
31 #include "chrome/browser/ui/omnibox/location_bar.h" | 38 #include "chrome/browser/ui/omnibox/location_bar.h" |
32 #include "chrome/browser/ui/status_bubble.h" | 39 #include "chrome/browser/ui/status_bubble.h" |
33 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 40 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
34 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 41 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
35 #include "chrome/browser/ui/webui/feedback_ui.h" | 42 #include "chrome/browser/ui/webui/feedback_ui.h" |
36 #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h" | 43 #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h" |
| 44 #include "chrome/browser/web_applications/web_app.h" |
37 #include "chrome/common/chrome_switches.h" | 45 #include "chrome/common/chrome_switches.h" |
38 #include "chrome/common/net/url_util.h" | 46 #include "chrome/common/net/url_util.h" |
39 #include "chrome/common/pref_names.h" | 47 #include "chrome/common/pref_names.h" |
| 48 #include "content/public/common/content_restriction.h" |
40 #include "content/public/browser/navigation_controller.h" | 49 #include "content/public/browser/navigation_controller.h" |
41 #include "content/public/browser/navigation_entry.h" | 50 #include "content/public/browser/navigation_entry.h" |
42 #include "content/public/browser/page_navigator.h" | 51 #include "content/public/browser/page_navigator.h" |
43 #include "content/public/browser/render_view_host.h" | 52 #include "content/public/browser/render_view_host.h" |
44 #include "content/public/browser/user_metrics.h" | 53 #include "content/public/browser/user_metrics.h" |
45 #include "content/public/browser/web_contents.h" | 54 #include "content/public/browser/web_contents.h" |
46 #include "content/public/browser/web_contents_view.h" | 55 #include "content/public/browser/web_contents_view.h" |
47 #include "content/public/common/url_constants.h" | 56 #include "content/public/common/url_constants.h" |
48 #include "net/base/escape.h" | 57 #include "net/base/escape.h" |
49 #include "webkit/glue/webkit_glue.h" | 58 #include "webkit/glue/webkit_glue.h" |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 WebContents* web_contents = GetOrCloneTabForDisposition(browser, disposition); | 125 WebContents* web_contents = GetOrCloneTabForDisposition(browser, disposition); |
117 web_contents->UserGestureDone(); | 126 web_contents->UserGestureDone(); |
118 if (!web_contents->FocusLocationBarByDefault()) | 127 if (!web_contents->FocusLocationBarByDefault()) |
119 web_contents->Focus(); | 128 web_contents->Focus(); |
120 if (ignore_cache) | 129 if (ignore_cache) |
121 web_contents->GetController().ReloadIgnoringCache(true); | 130 web_contents->GetController().ReloadIgnoringCache(true); |
122 else | 131 else |
123 web_contents->GetController().Reload(true); | 132 web_contents->GetController().Reload(true); |
124 } | 133 } |
125 | 134 |
| 135 bool HasConstrainedWindow(const Browser* browser) { |
| 136 TabContents* tab_contents = browser->GetActiveTabContents(); |
| 137 return tab_contents && tab_contents->constrained_window_tab_helper()-> |
| 138 constrained_window_count(); |
| 139 } |
| 140 |
| 141 bool PrintPreviewShowing(const Browser* browser) { |
| 142 TabContents* contents = browser->GetActiveTabContents(); |
| 143 printing::PrintPreviewTabController* controller = |
| 144 printing::PrintPreviewTabController::GetInstance(); |
| 145 return controller && (controller->GetPrintPreviewForTab(contents) || |
| 146 controller->is_creating_print_preview_tab()); |
| 147 } |
| 148 |
126 } // namespace | 149 } // namespace |
127 | 150 |
| 151 bool IsCommandEnabled(Browser* browser, int command) { |
| 152 return browser->command_controller()->command_updater()->IsCommandEnabled( |
| 153 command); |
| 154 } |
| 155 |
| 156 bool SupportsCommand(Browser* browser, int command) { |
| 157 return browser->command_controller()->command_updater()->SupportsCommand( |
| 158 command); |
| 159 } |
| 160 |
| 161 bool ExecuteCommand(Browser* browser, int command) { |
| 162 return browser->command_controller()->command_updater()->ExecuteCommand( |
| 163 command); |
| 164 } |
| 165 |
| 166 bool ExecuteCommandWithDisposition(Browser* browser, |
| 167 int command, |
| 168 WindowOpenDisposition disposition) { |
| 169 return browser->command_controller()->command_updater()-> |
| 170 ExecuteCommandWithDisposition(command, disposition); |
| 171 } |
| 172 |
| 173 void UpdateCommandEnabled(Browser* browser, int command, bool enabled) { |
| 174 browser->command_controller()->command_updater()->UpdateCommandEnabled( |
| 175 command, enabled); |
| 176 } |
| 177 |
| 178 void AddCommandObserver(Browser* browser, |
| 179 int command, |
| 180 CommandObserver* observer) { |
| 181 browser->command_controller()->command_updater()->AddCommandObserver( |
| 182 command, observer); |
| 183 } |
| 184 |
| 185 void RemoveCommandObserver(Browser* browser, |
| 186 int command, |
| 187 CommandObserver* observer) { |
| 188 browser->command_controller()->command_updater()->RemoveCommandObserver( |
| 189 command, observer); |
| 190 } |
| 191 |
| 192 int GetContentRestrictions(const Browser* browser) { |
| 193 int content_restrictions = 0; |
| 194 WebContents* current_tab = browser->GetActiveWebContents(); |
| 195 if (current_tab) { |
| 196 content_restrictions = current_tab->GetContentRestrictions(); |
| 197 NavigationEntry* active_entry = |
| 198 current_tab->GetController().GetActiveEntry(); |
| 199 // See comment in UpdateCommandsForTabState about why we call url(). |
| 200 if (!download_util::IsSavableURL( |
| 201 active_entry ? active_entry->GetURL() : GURL()) || |
| 202 current_tab->ShowingInterstitialPage()) |
| 203 content_restrictions |= content::CONTENT_RESTRICTION_SAVE; |
| 204 if (current_tab->ShowingInterstitialPage()) |
| 205 content_restrictions |= content::CONTENT_RESTRICTION_PRINT; |
| 206 } |
| 207 return content_restrictions; |
| 208 } |
| 209 |
128 void NewEmptyWindow(Profile* profile) { | 210 void NewEmptyWindow(Profile* profile) { |
129 bool incognito = profile->IsOffTheRecord(); | 211 bool incognito = profile->IsOffTheRecord(); |
130 PrefService* prefs = profile->GetPrefs(); | 212 PrefService* prefs = profile->GetPrefs(); |
131 if (incognito) { | 213 if (incognito) { |
132 if (IncognitoModePrefs::GetAvailability(prefs) == | 214 if (IncognitoModePrefs::GetAvailability(prefs) == |
133 IncognitoModePrefs::DISABLED) { | 215 IncognitoModePrefs::DISABLED) { |
134 incognito = false; | 216 incognito = false; |
135 } | 217 } |
136 } else { | 218 } else { |
137 if (browser_defaults::kAlwaysOpenIncognitoWindow && | 219 if (browser_defaults::kAlwaysOpenIncognitoWindow && |
(...skipping 30 matching lines...) Expand all Loading... |
168 service->RestoreMostRecentEntry(NULL); | 250 service->RestoreMostRecentEntry(NULL); |
169 } | 251 } |
170 | 252 |
171 void OpenURLOffTheRecord(Profile* profile, const GURL& url) { | 253 void OpenURLOffTheRecord(Profile* profile, const GURL& url) { |
172 Browser* browser = browser::FindOrCreateTabbedBrowser( | 254 Browser* browser = browser::FindOrCreateTabbedBrowser( |
173 profile->GetOffTheRecordProfile()); | 255 profile->GetOffTheRecordProfile()); |
174 browser->AddSelectedTabWithURL(url, content::PAGE_TRANSITION_LINK); | 256 browser->AddSelectedTabWithURL(url, content::PAGE_TRANSITION_LINK); |
175 browser->window()->Show(); | 257 browser->window()->Show(); |
176 } | 258 } |
177 | 259 |
178 bool CanGoBack(Browser* browser) { | 260 bool CanGoBack(const Browser* browser) { |
179 return browser->GetActiveWebContents()->GetController().CanGoBack(); | 261 return browser->GetActiveWebContents()->GetController().CanGoBack(); |
180 } | 262 } |
181 | 263 |
182 void GoBack(Browser* browser, WindowOpenDisposition disposition) { | 264 void GoBack(Browser* browser, WindowOpenDisposition disposition) { |
183 content::RecordAction(UserMetricsAction("Back")); | 265 content::RecordAction(UserMetricsAction("Back")); |
184 | 266 |
185 TabContents* current_tab = browser->GetActiveTabContents(); | 267 TabContents* current_tab = browser->GetActiveTabContents(); |
186 if (CanGoBack(browser)) { | 268 if (CanGoBack(browser)) { |
187 WebContents* new_tab = GetOrCloneTabForDisposition(browser, disposition); | 269 WebContents* new_tab = GetOrCloneTabForDisposition(browser, disposition); |
188 // If we are on an interstitial page and clone the tab, it won't be copied | 270 // If we are on an interstitial page and clone the tab, it won't be copied |
189 // to the new tab, so we don't need to go back. | 271 // to the new tab, so we don't need to go back. |
190 if (current_tab->web_contents()->ShowingInterstitialPage() && | 272 if (current_tab->web_contents()->ShowingInterstitialPage() && |
191 (new_tab != current_tab->web_contents())) | 273 (new_tab != current_tab->web_contents())) |
192 return; | 274 return; |
193 new_tab->GetController().GoBack(); | 275 new_tab->GetController().GoBack(); |
194 } | 276 } |
195 } | 277 } |
196 | 278 |
197 bool CanGoForward(Browser* browser) { | 279 bool CanGoForward(const Browser* browser) { |
198 return browser->GetActiveWebContents()->GetController().CanGoForward(); | 280 return browser->GetActiveWebContents()->GetController().CanGoForward(); |
199 } | 281 } |
200 | 282 |
201 void GoForward(Browser* browser, WindowOpenDisposition disposition) { | 283 void GoForward(Browser* browser, WindowOpenDisposition disposition) { |
202 content::RecordAction(UserMetricsAction("Forward")); | 284 content::RecordAction(UserMetricsAction("Forward")); |
203 if (CanGoForward(browser)) { | 285 if (CanGoForward(browser)) { |
204 GetOrCloneTabForDisposition(browser, disposition)-> | 286 GetOrCloneTabForDisposition(browser, disposition)-> |
205 GetController().GoForward(); | 287 GetController().GoForward(); |
206 } | 288 } |
207 } | 289 } |
(...skipping 12 matching lines...) Expand all Loading... |
220 void Reload(Browser* browser, WindowOpenDisposition disposition) { | 302 void Reload(Browser* browser, WindowOpenDisposition disposition) { |
221 content::RecordAction(UserMetricsAction("Reload")); | 303 content::RecordAction(UserMetricsAction("Reload")); |
222 ReloadInternal(browser, disposition, false); | 304 ReloadInternal(browser, disposition, false); |
223 } | 305 } |
224 | 306 |
225 void ReloadIgnoringCache(Browser* browser, WindowOpenDisposition disposition) { | 307 void ReloadIgnoringCache(Browser* browser, WindowOpenDisposition disposition) { |
226 content::RecordAction(UserMetricsAction("ReloadIgnoringCache")); | 308 content::RecordAction(UserMetricsAction("ReloadIgnoringCache")); |
227 ReloadInternal(browser, disposition, true); | 309 ReloadInternal(browser, disposition, true); |
228 } | 310 } |
229 | 311 |
| 312 bool CanReload(const Browser* browser) { |
| 313 return !browser->is_devtools(); |
| 314 } |
| 315 |
230 void Home(Browser* browser, WindowOpenDisposition disposition) { | 316 void Home(Browser* browser, WindowOpenDisposition disposition) { |
231 content::RecordAction(UserMetricsAction("Home")); | 317 content::RecordAction(UserMetricsAction("Home")); |
232 browser->OpenURL(OpenURLParams( | 318 browser->OpenURL(OpenURLParams( |
233 browser->profile()->GetHomePage(), Referrer(), disposition, | 319 browser->profile()->GetHomePage(), Referrer(), disposition, |
234 content::PageTransitionFromInt( | 320 content::PageTransitionFromInt( |
235 content::PAGE_TRANSITION_AUTO_BOOKMARK | | 321 content::PAGE_TRANSITION_AUTO_BOOKMARK | |
236 content::PAGE_TRANSITION_HOME_PAGE), | 322 content::PAGE_TRANSITION_HOME_PAGE), |
237 false)); | 323 false)); |
238 } | 324 } |
239 | 325 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 // See http://crbug.com/6380. | 394 // See http://crbug.com/6380. |
309 b->GetActiveWebContents()->GetView()->RestoreFocus(); | 395 b->GetActiveWebContents()->GetView()->RestoreFocus(); |
310 } | 396 } |
311 } | 397 } |
312 | 398 |
313 void CloseTab(Browser* browser) { | 399 void CloseTab(Browser* browser) { |
314 content::RecordAction(UserMetricsAction("CloseTab_Accelerator")); | 400 content::RecordAction(UserMetricsAction("CloseTab_Accelerator")); |
315 browser->tab_strip_model()->CloseSelectedTabs(); | 401 browser->tab_strip_model()->CloseSelectedTabs(); |
316 } | 402 } |
317 | 403 |
| 404 void RestoreTab(Browser* browser) { |
| 405 content::RecordAction(UserMetricsAction("RestoreTab")); |
| 406 TabRestoreService* service = |
| 407 TabRestoreServiceFactory::GetForProfile(browser->profile()); |
| 408 if (service) |
| 409 service->RestoreMostRecentEntry(browser->tab_restore_service_delegate()); |
| 410 } |
| 411 |
| 412 bool CanRestoreTab(const Browser* browser) { |
| 413 TabRestoreService* service = |
| 414 TabRestoreServiceFactory::GetForProfile(browser->profile()); |
| 415 return service && !service->entries().empty(); |
| 416 } |
| 417 |
318 void SelectNextTab(Browser* browser) { | 418 void SelectNextTab(Browser* browser) { |
319 content::RecordAction(UserMetricsAction("SelectNextTab")); | 419 content::RecordAction(UserMetricsAction("SelectNextTab")); |
320 browser->tab_strip_model()->SelectNextTab(); | 420 browser->tab_strip_model()->SelectNextTab(); |
321 } | 421 } |
322 | 422 |
323 void SelectPreviousTab(Browser* browser) { | 423 void SelectPreviousTab(Browser* browser) { |
324 content::RecordAction(UserMetricsAction("SelectPrevTab")); | 424 content::RecordAction(UserMetricsAction("SelectPrevTab")); |
325 browser->tab_strip_model()->SelectPreviousTab(); | 425 browser->tab_strip_model()->SelectPreviousTab(); |
326 } | 426 } |
327 | 427 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 void SelectLastTab(Browser* browser) { | 459 void SelectLastTab(Browser* browser) { |
360 content::RecordAction(UserMetricsAction("SelectLastTab")); | 460 content::RecordAction(UserMetricsAction("SelectLastTab")); |
361 browser->tab_strip_model()->SelectLastTab(); | 461 browser->tab_strip_model()->SelectLastTab(); |
362 } | 462 } |
363 | 463 |
364 void DuplicateTab(Browser* browser) { | 464 void DuplicateTab(Browser* browser) { |
365 content::RecordAction(UserMetricsAction("Duplicate")); | 465 content::RecordAction(UserMetricsAction("Duplicate")); |
366 browser->DuplicateContentsAt(browser->active_index()); | 466 browser->DuplicateContentsAt(browser->active_index()); |
367 } | 467 } |
368 | 468 |
| 469 bool CanDuplicateTab(const Browser* browser) { |
| 470 WebContents* contents = browser->GetActiveWebContents(); |
| 471 return contents && contents->GetController().GetLastCommittedEntry(); |
| 472 } |
| 473 |
369 void WriteCurrentURLToClipboard(Browser* browser) { | 474 void WriteCurrentURLToClipboard(Browser* browser) { |
370 // TODO(ericu): There isn't currently a metric for this. Should there be? | 475 // TODO(ericu): There isn't currently a metric for this. Should there be? |
371 // We don't appear to track the action when it comes from the | 476 // We don't appear to track the action when it comes from the |
372 // RenderContextViewMenu. | 477 // RenderContextViewMenu. |
373 | 478 |
374 WebContents* contents = browser->GetActiveWebContents(); | 479 WebContents* contents = browser->GetActiveWebContents(); |
375 if (!browser->toolbar_model()->ShouldDisplayURL()) | 480 if (!browser->toolbar_model()->ShouldDisplayURL()) |
376 return; | 481 return; |
377 | 482 |
378 chrome_common_net::WriteURLToClipboard( | 483 chrome_common_net::WriteURLToClipboard( |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 bookmark_utils::AddIfNotBookmarked(model, url, title); | 520 bookmark_utils::AddIfNotBookmarked(model, url, title); |
416 // Make sure the model actually added a bookmark before showing the star. A | 521 // Make sure the model actually added a bookmark before showing the star. A |
417 // bookmark isn't created if the url is invalid. | 522 // bookmark isn't created if the url is invalid. |
418 if (browser->window()->IsActive() && model->IsBookmarked(url)) { | 523 if (browser->window()->IsActive() && model->IsBookmarked(url)) { |
419 // Only show the bubble if the window is active, otherwise we may get into | 524 // Only show the bubble if the window is active, otherwise we may get into |
420 // weird situations where the bubble is deleted as soon as it is shown. | 525 // weird situations where the bubble is deleted as soon as it is shown. |
421 browser->window()->ShowBookmarkBubble(url, was_bookmarked); | 526 browser->window()->ShowBookmarkBubble(url, was_bookmarked); |
422 } | 527 } |
423 } | 528 } |
424 | 529 |
| 530 bool CanBookmarkCurrentPage(const Browser* browser) { |
| 531 BookmarkModel* model = browser->profile()->GetBookmarkModel(); |
| 532 return browser_defaults::bookmarks_enabled && |
| 533 browser->profile()->GetPrefs()->GetBoolean( |
| 534 prefs::kEditBookmarksEnabled) && |
| 535 model && model->IsLoaded() && browser->is_type_tabbed(); |
| 536 } |
| 537 |
| 538 void BookmarkAllTabs(Browser* browser) { |
| 539 BookmarkEditor::ShowBookmarkAllTabsDialog(browser); |
| 540 } |
| 541 |
| 542 bool CanBookmarkAllTabs(const Browser* browser) { |
| 543 return browser->tab_count() > 1 && CanBookmarkCurrentPage(browser); |
| 544 } |
| 545 |
425 #if !defined(OS_WIN) | 546 #if !defined(OS_WIN) |
426 void PinCurrentPageToStartScreen(Browser* browser) { | 547 void PinCurrentPageToStartScreen(Browser* browser) { |
427 } | 548 } |
428 #endif | 549 #endif |
429 | 550 |
430 void SavePage(Browser* browser) { | 551 void SavePage(Browser* browser) { |
431 content::RecordAction(UserMetricsAction("SavePage")); | 552 content::RecordAction(UserMetricsAction("SavePage")); |
432 WebContents* current_tab = browser->GetActiveWebContents(); | 553 WebContents* current_tab = browser->GetActiveWebContents(); |
433 if (current_tab && current_tab->GetContentsMimeType() == "application/pdf") | 554 if (current_tab && current_tab->GetContentsMimeType() == "application/pdf") |
434 content::RecordAction(UserMetricsAction("PDF.SavePage")); | 555 content::RecordAction(UserMetricsAction("PDF.SavePage")); |
435 current_tab->OnSavePage(); | 556 current_tab->OnSavePage(); |
436 } | 557 } |
437 | 558 |
| 559 bool CanSavePage(const Browser* browser) { |
| 560 // LocalState can be NULL in tests. |
| 561 if (g_browser_process->local_state() && |
| 562 !g_browser_process->local_state()->GetBoolean( |
| 563 prefs::kAllowFileSelectionDialogs)) { |
| 564 return false; |
| 565 } |
| 566 return !browser->is_devtools() && |
| 567 !(GetContentRestrictions(browser) & content::CONTENT_RESTRICTION_SAVE); |
| 568 } |
| 569 |
438 void ShowFindBar(Browser* browser) { | 570 void ShowFindBar(Browser* browser) { |
439 browser->GetFindBarController()->Show(); | 571 browser->GetFindBarController()->Show(); |
440 } | 572 } |
441 | 573 |
442 void ShowPageInfo(Browser* browser, | 574 void ShowPageInfo(Browser* browser, |
443 content::WebContents* web_contents, | 575 content::WebContents* web_contents, |
444 const GURL& url, | 576 const GURL& url, |
445 const SSLStatus& ssl, | 577 const SSLStatus& ssl, |
446 bool show_history) { | 578 bool show_history) { |
447 Profile* profile = Profile::FromBrowserContext( | 579 Profile* profile = Profile::FromBrowserContext( |
(...skipping 18 matching lines...) Expand all Loading... |
466 | 598 |
467 void Print(Browser* browser) { | 599 void Print(Browser* browser) { |
468 if (g_browser_process->local_state()->GetBoolean( | 600 if (g_browser_process->local_state()->GetBoolean( |
469 prefs::kPrintPreviewDisabled)) { | 601 prefs::kPrintPreviewDisabled)) { |
470 browser->GetActiveTabContents()->print_view_manager()->PrintNow(); | 602 browser->GetActiveTabContents()->print_view_manager()->PrintNow(); |
471 } else { | 603 } else { |
472 browser->GetActiveTabContents()->print_view_manager()->PrintPreviewNow(); | 604 browser->GetActiveTabContents()->print_view_manager()->PrintPreviewNow(); |
473 } | 605 } |
474 } | 606 } |
475 | 607 |
| 608 bool CanPrint(const Browser* browser) { |
| 609 // LocalState can be NULL in tests. |
| 610 if (g_browser_process->local_state() && |
| 611 !g_browser_process->local_state()->GetBoolean(prefs::kPrintingEnabled)) { |
| 612 return false; |
| 613 } |
| 614 |
| 615 // Do not print when a constrained window is showing. It's confusing. |
| 616 return !(HasConstrainedWindow(browser) || |
| 617 GetContentRestrictions(browser) & content::CONTENT_RESTRICTION_PRINT); |
| 618 } |
| 619 |
476 void AdvancedPrint(Browser* browser) { | 620 void AdvancedPrint(Browser* browser) { |
477 browser->GetActiveTabContents()->print_view_manager()->AdvancedPrintNow(); | 621 browser->GetActiveTabContents()->print_view_manager()->AdvancedPrintNow(); |
478 } | 622 } |
479 | 623 |
| 624 bool CanAdvancedPrint(const Browser* browser) { |
| 625 // LocalState can be NULL in tests. |
| 626 if (g_browser_process->local_state() && |
| 627 !g_browser_process->local_state()->GetBoolean(prefs::kPrintingEnabled)) { |
| 628 return false; |
| 629 } |
| 630 |
| 631 // It is always possible to advanced print when print preview is visible. |
| 632 return PrintPreviewShowing(browser) || CanPrint(browser); |
| 633 } |
| 634 |
480 void EmailPageLocation(Browser* browser) { | 635 void EmailPageLocation(Browser* browser) { |
481 content::RecordAction(UserMetricsAction("EmailPageLocation")); | 636 content::RecordAction(UserMetricsAction("EmailPageLocation")); |
482 WebContents* wc = browser->GetActiveWebContents(); | 637 WebContents* wc = browser->GetActiveWebContents(); |
483 DCHECK(wc); | 638 DCHECK(wc); |
484 | 639 |
485 std::string title = net::EscapeQueryParamValue( | 640 std::string title = net::EscapeQueryParamValue( |
486 UTF16ToUTF8(wc->GetTitle()), false); | 641 UTF16ToUTF8(wc->GetTitle()), false); |
487 std::string page_url = net::EscapeQueryParamValue(wc->GetURL().spec(), false); | 642 std::string page_url = net::EscapeQueryParamValue(wc->GetURL().spec(), false); |
488 std::string mailto = std::string("mailto:?subject=Fwd:%20") + | 643 std::string mailto = std::string("mailto:?subject=Fwd:%20") + |
489 title + "&body=%0A%0A" + page_url; | 644 title + "&body=%0A%0A" + page_url; |
490 platform_util::OpenExternal(GURL(mailto)); | 645 platform_util::OpenExternal(GURL(mailto)); |
491 } | 646 } |
492 | 647 |
| 648 bool CanEmailPageLocation(const Browser* browser) { |
| 649 return browser->toolbar_model()->ShouldDisplayURL() && |
| 650 browser->GetActiveWebContents()->GetURL().is_valid(); |
| 651 } |
| 652 |
493 void Cut(Browser* browser) { | 653 void Cut(Browser* browser) { |
494 content::RecordAction(UserMetricsAction("Cut")); | 654 content::RecordAction(UserMetricsAction("Cut")); |
495 browser->window()->Cut(); | 655 browser->window()->Cut(); |
496 } | 656 } |
497 | 657 |
498 void Copy(Browser* browser) { | 658 void Copy(Browser* browser) { |
499 content::RecordAction(UserMetricsAction("Copy")); | 659 content::RecordAction(UserMetricsAction("Copy")); |
500 browser->window()->Copy(); | 660 browser->window()->Copy(); |
501 } | 661 } |
502 | 662 |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
749 SessionService* session_service = | 909 SessionService* session_service = |
750 SessionServiceFactory::GetForProfileIfExisting(browser->profile()); | 910 SessionServiceFactory::GetForProfileIfExisting(browser->profile()); |
751 if (session_service) | 911 if (session_service) |
752 session_service->TabRestored(view_source_contents, false); | 912 session_service->TabRestored(view_source_contents, false); |
753 } | 913 } |
754 | 914 |
755 void ViewSelectedSource(Browser* browser) { | 915 void ViewSelectedSource(Browser* browser) { |
756 ViewSource(browser, browser->GetActiveTabContents()); | 916 ViewSource(browser, browser->GetActiveTabContents()); |
757 } | 917 } |
758 | 918 |
| 919 bool CanViewSource(const Browser* browser) { |
| 920 return browser->GetActiveWebContents()->GetController().CanViewSource(); |
| 921 } |
| 922 |
| 923 bool CanCreateApplicationShortcuts(const Browser* browser) { |
| 924 return web_app::IsValidUrl(browser->GetActiveWebContents()->GetURL()); |
| 925 } |
| 926 |
759 } // namespace chrome | 927 } // namespace chrome |
OLD | NEW |