diff options
-rw-r--r-- | chrome/app/chrome_command_ids.h | 1 | ||||
-rw-r--r-- | chrome/app/media_router_strings.grdp | 3 | ||||
-rw-r--r-- | chrome/browser/renderer_context_menu/render_view_context_menu.cc | 53 | ||||
-rw-r--r-- | chrome/browser/renderer_context_menu/render_view_context_menu.h | 1 | ||||
-rw-r--r-- | chrome/browser/ui/browser_command_controller.cc | 10 | ||||
-rw-r--r-- | chrome/browser/ui/browser_command_controller.h | 5 | ||||
-rw-r--r-- | chrome/browser/ui/browser_commands.cc | 22 | ||||
-rw-r--r-- | chrome/browser/ui/browser_commands.h | 2 | ||||
-rw-r--r-- | chrome/browser/ui/toolbar/wrench_menu_model.cc | 2 |
9 files changed, 97 insertions, 2 deletions
diff --git a/chrome/app/chrome_command_ids.h b/chrome/app/chrome_command_ids.h index 6ca7b93..176bc62 100644 --- a/chrome/app/chrome_command_ids.h +++ b/chrome/app/chrome_command_ids.h @@ -87,6 +87,7 @@ #define IDC_BASIC_PRINT 35007 #define IDC_TRANSLATE_PAGE 35009 #define IDC_MANAGE_PASSWORDS_FOR_PAGE 35010 +#define IDC_ROUTE_MEDIA 35011 // When adding a new encoding to this list, be sure to append it to the // EncodingMenuController::kValidEncodingIds array in diff --git a/chrome/app/media_router_strings.grdp b/chrome/app/media_router_strings.grdp index 7f62bad..254c353 100644 --- a/chrome/app/media_router_strings.grdp +++ b/chrome/app/media_router_strings.grdp @@ -8,6 +8,9 @@ <message name="IDS_MEDIA_ROUTER_SHARE_YOUR_SCREEN_TEXT" desc="Tooltip for the Media Router Action icon, which appears in the toolbar. The tooltip appears on mouseover of the icon."> Share your screen </message> + <message name="IDS_MEDIA_ROUTER_MENU_ITEM_TITLE" desc="Title of menu item for Media Router, which appears in the overflow menu and page contextual menus."> + Cast... + </message> <!-- Cast Modes --> <message name="IDS_MEDIA_ROUTER_DEFAULT_CAST_MODE" desc="Title for the default cast mode, which is used when the host is cast enabled. This is shown as a dropdown option, and if selected, also appears as the header of a list of devices."> diff --git a/chrome/browser/renderer_context_menu/render_view_context_menu.cc b/chrome/browser/renderer_context_menu/render_view_context_menu.cc index 0e637d7..12d8b73 100644 --- a/chrome/browser/renderer_context_menu/render_view_context_menu.cc +++ b/chrome/browser/renderer_context_menu/render_view_context_menu.cc @@ -30,6 +30,7 @@ #include "chrome/browser/download/download_stats.h" #include "chrome/browser/extensions/devtools_util.h" #include "chrome/browser/extensions/extension_service.h" +#include "chrome/browser/media/router/media_router_dialog_controller.h" #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h" #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_factory.h" #include "chrome/browser/password_manager/chrome_password_manager_client.h" @@ -53,6 +54,7 @@ #include "chrome/browser/ui/chrome_pages.h" #include "chrome/browser/ui/search_engines/search_engine_tab_helper.h" #include "chrome/browser/ui/tab_contents/core_tab_helper.h" +#include "chrome/browser/ui/tabs/tab_strip_model.h" #include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/content_restriction.h" @@ -74,6 +76,7 @@ #include "components/translate/core/browser/translate_prefs.h" #include "components/url_formatter/url_formatter.h" #include "components/user_prefs/user_prefs.h" +#include "components/web_modal/web_contents_modal_dialog_manager.h" #include "content/public/browser/child_process_security_policy.h" #include "content/public/browser/download_manager.h" #include "content/public/browser/download_save_info.h" @@ -239,9 +242,10 @@ const struct UmaEnumCommandIdPair { {65, -1, IDC_WRITING_DIRECTION_RTL}, {66, -1, IDC_CONTENT_CONTEXT_LOAD_ORIGINAL_IMAGE}, {67, -1, IDC_CONTENT_CONTEXT_FORCESAVEPASSWORD}, + {68, -1, IDC_ROUTE_MEDIA}, // Add new items here and use |enum_id| from the next line. // Also, add new items to RenderViewContextMenuItem enum in histograms.xml. - {68, -1, 0}, // Must be the last. Increment |enum_id| when new IDC + {69, -1, 0}, // Must be the last. Increment |enum_id| when new IDC // was added. }; @@ -863,6 +867,7 @@ void RenderViewContextMenu::AppendAudioItems() { IDS_CONTENT_CONTEXT_SAVEAUDIOAS); menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_COPYAVLOCATION, IDS_CONTENT_CONTEXT_COPYAUDIOLOCATION); + AppendMediaRouterItem(); } void RenderViewContextMenu::AppendCanvasItems() { @@ -880,6 +885,7 @@ void RenderViewContextMenu::AppendVideoItems() { IDS_CONTENT_CONTEXT_SAVEVIDEOAS); menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_COPYAVLOCATION, IDS_CONTENT_CONTEXT_COPYVIDEOLOCATION); + AppendMediaRouterItem(); } void RenderViewContextMenu::AppendPluginItems() { @@ -908,6 +914,7 @@ void RenderViewContextMenu::AppendPageItems() { menu_model_.AddItemWithStringId(IDC_SAVE_PAGE, IDS_CONTENT_CONTEXT_SAVEPAGEAS); menu_model_.AddItemWithStringId(IDC_PRINT, IDS_CONTENT_CONTEXT_PRINT); + AppendMediaRouterItem(); if (TranslateService::IsTranslatableURL(params_.page_url)) { std::string locale = g_browser_process->GetApplicationLocale(); @@ -935,6 +942,12 @@ void RenderViewContextMenu::AppendPrintItem() { } } +void RenderViewContextMenu::AppendMediaRouterItem() { + if (switches::MediaRouterEnabled() && !browser_context_->IsOffTheRecord()) + menu_model_.AddItemWithStringId(IDC_ROUTE_MEDIA, + IDS_MEDIA_ROUTER_MENU_ITEM_TITLE); +} + void RenderViewContextMenu::AppendRotationItems() { if (params_.media_flags & WebContextMenuData::MediaCanRotate) { menu_model_.AddSeparator(ui::NORMAL_SEPARATOR); @@ -1387,6 +1400,26 @@ bool RenderViewContextMenu::IsCommandIdEnabled(int id) const { case IDC_CONTENT_CONTEXT_FORCESAVEPASSWORD: return true; + case IDC_ROUTE_MEDIA: { + DCHECK(switches::MediaRouterEnabled()); + + // Disable the command if there is an active modal dialog. + Browser* browser = + chrome::FindBrowserWithWebContents(source_web_contents_); + if (!browser || browser->profile()->IsOffTheRecord()) + return false; + + WebContents* web_contents = + browser->tab_strip_model()->GetActiveWebContents(); + if (!web_contents) + return false; + + const web_modal::WebContentsModalDialogManager* manager = + web_modal::WebContentsModalDialogManager::FromWebContents( + web_contents); + return !manager || !manager->IsDialogActive(); + } + default: NOTREACHED(); return false; @@ -1661,6 +1694,24 @@ void RenderViewContextMenu::ExecuteCommand(int id, int event_flags) { break; } + case IDC_ROUTE_MEDIA: { + DCHECK(switches::MediaRouterEnabled()); + + Browser* browser = + chrome::FindBrowserWithWebContents(source_web_contents_); + DCHECK(browser && !browser->profile()->IsOffTheRecord()); + + media_router::MediaRouterDialogController* dialog_controller = + media_router::MediaRouterDialogController::GetOrCreateForWebContents( + source_web_contents_); + + if (!dialog_controller) + return; + + dialog_controller->ShowMediaRouterDialog(); + break; + } + case IDC_VIEW_SOURCE: embedder_web_contents_->ViewSource(); break; diff --git a/chrome/browser/renderer_context_menu/render_view_context_menu.h b/chrome/browser/renderer_context_menu/render_view_context_menu.h index adbb515..e198d4f 100644 --- a/chrome/browser/renderer_context_menu/render_view_context_menu.h +++ b/chrome/browser/renderer_context_menu/render_view_context_menu.h @@ -123,6 +123,7 @@ class RenderViewContextMenu : public RenderViewContextMenuBase { void AppendPageItems(); void AppendCopyItem(); void AppendPrintItem(); + void AppendMediaRouterItem(); void AppendRotationItems(); void AppendEditableItems(); void AppendLanguageSettings(); diff --git a/chrome/browser/ui/browser_command_controller.cc b/chrome/browser/ui/browser_command_controller.cc index 1de24d7..395cdc9 100644 --- a/chrome/browser/ui/browser_command_controller.cc +++ b/chrome/browser/ui/browser_command_controller.cc @@ -778,6 +778,9 @@ void BrowserCommandController::ExecuteCommandWithDisposition( ash::accelerators::ToggleTouchHudProjection(); break; #endif + case IDC_ROUTE_MEDIA: + RouteMedia(browser_); + break; default: LOG(WARNING) << "Received Unimplemented Command: " << id; @@ -821,6 +824,7 @@ void BrowserCommandController::TabBlockedStateChanged( PrintingStateChanged(); FullscreenStateChanged(); UpdateCommandsForFind(); + UpdateCommandsForMediaRouter(); } //////////////////////////////////////////////////////////////////////////////// @@ -1137,6 +1141,7 @@ void BrowserCommandController::UpdateCommandsForTabState() { UpdateCommandsForContentRestrictionState(); UpdateCommandsForBookmarkEditing(); UpdateCommandsForFind(); + UpdateCommandsForMediaRouter(); // Update the zoom commands when an active tab is selected. UpdateCommandsForZoomState(); } @@ -1343,6 +1348,11 @@ void BrowserCommandController::UpdateCommandsForFind() { command_updater_.UpdateCommandEnabled(IDC_FIND_PREVIOUS, enabled); } +void BrowserCommandController::UpdateCommandsForMediaRouter() { + command_updater_.UpdateCommandEnabled(IDC_ROUTE_MEDIA, + CanRouteMedia(browser_)); +} + void BrowserCommandController::AddInterstitialObservers(WebContents* contents) { interstitial_observers_.push_back(new InterstitialObserver(this, contents)); } diff --git a/chrome/browser/ui/browser_command_controller.h b/chrome/browser/ui/browser_command_controller.h index 702534fe..2a8730e 100644 --- a/chrome/browser/ui/browser_command_controller.h +++ b/chrome/browser/ui/browser_command_controller.h @@ -155,10 +155,13 @@ class BrowserCommandController : public CommandUpdaterDelegate, // |force| is true if the button should change its icon immediately. void UpdateReloadStopState(bool is_loading, bool force); + void UpdateTabRestoreCommandState(); + // Updates commands for find. void UpdateCommandsForFind(); - void UpdateTabRestoreCommandState(); + // Updates commands for Media Router. + void UpdateCommandsForMediaRouter(); // Add/remove observers for interstitial attachment/detachment from // |contents|. diff --git a/chrome/browser/ui/browser_commands.cc b/chrome/browser/ui/browser_commands.cc index cb8a4dc..f90be0c 100644 --- a/chrome/browser/ui/browser_commands.cc +++ b/chrome/browser/ui/browser_commands.cc @@ -17,6 +17,7 @@ #include "chrome/browser/devtools/devtools_window.h" #include "chrome/browser/dom_distiller/tab_utils.h" #include "chrome/browser/lifetime/application_lifetime.h" +#include "chrome/browser/media/router/media_router_dialog_controller.h" #include "chrome/browser/platform_util.h" #include "chrome/browser/prefs/incognito_mode_prefs.h" #include "chrome/browser/profiles/profile.h" @@ -911,6 +912,27 @@ bool CanBasicPrint(Browser* browser) { } #endif // ENABLE_BASIC_PRINTING +bool CanRouteMedia(Browser* browser) { + if (!switches::MediaRouterEnabled() || browser->profile()->IsOffTheRecord()) + return false; + + // Do not allow user to open Media Router dialog when there is already an + // active modal dialog. This avoids overlapping dialogs. + return !IsShowingWebContentsModalDialog(browser); +} + +void RouteMedia(Browser* browser) { + DCHECK(CanRouteMedia(browser)); + + media_router::MediaRouterDialogController* dialog_controller = + media_router::MediaRouterDialogController::GetOrCreateForWebContents( + browser->tab_strip_model()->GetActiveWebContents()); + if (!dialog_controller) + return; + + dialog_controller->ShowMediaRouterDialog(); +} + void EmailPageLocation(Browser* browser) { content::RecordAction(UserMetricsAction("EmailPageLocation")); WebContents* wc = browser->tab_strip_model()->GetActiveWebContents(); diff --git a/chrome/browser/ui/browser_commands.h b/chrome/browser/ui/browser_commands.h index d2d37ee..013db31 100644 --- a/chrome/browser/ui/browser_commands.h +++ b/chrome/browser/ui/browser_commands.h @@ -117,6 +117,8 @@ bool CanPrint(Browser* browser); void BasicPrint(Browser* browser); bool CanBasicPrint(Browser* browser); #endif // ENABLE_BASIC_PRINTING +bool CanRouteMedia(Browser* browser); +void RouteMedia(Browser* browser); void EmailPageLocation(Browser* browser); bool CanEmailPageLocation(const Browser* browser); void CutCopyPaste(Browser* browser, int command_id); diff --git a/chrome/browser/ui/toolbar/wrench_menu_model.cc b/chrome/browser/ui/toolbar/wrench_menu_model.cc index 805c906..7bbdb3c 100644 --- a/chrome/browser/ui/toolbar/wrench_menu_model.cc +++ b/chrome/browser/ui/toolbar/wrench_menu_model.cc @@ -898,6 +898,8 @@ void WrenchMenuModel::Build() { CreateZoomMenu(); AddItemWithStringId(IDC_PRINT, IDS_PRINT); + if (switches::MediaRouterEnabled() && !browser()->profile()->IsOffTheRecord()) + AddItemWithStringId(IDC_ROUTE_MEDIA, IDS_MEDIA_ROUTER_MENU_ITEM_TITLE); AddItemWithStringId(IDC_FIND, IDS_FIND); if (base::CommandLine::ForCurrentProcess()->HasSwitch( switches::kEnableDomDistiller)) |