diff options
author | ajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-23 23:06:56 +0000 |
---|---|---|
committer | ajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-23 23:06:56 +0000 |
commit | 581b87eb99683237b52cf727178c0492cf273eeb (patch) | |
tree | 516cf6d1b75dc380fa179d72f95579300d9fdfcb /chrome | |
parent | c72d7f9099a607ed546404a04a50402a9c3eeeb6 (diff) | |
download | chromium_src-581b87eb99683237b52cf727178c0492cf273eeb.zip chromium_src-581b87eb99683237b52cf727178c0492cf273eeb.tar.gz chromium_src-581b87eb99683237b52cf727178c0492cf273eeb.tar.bz2 |
Allow the browser to send actions back to the render for media element context menus.
Also renamed ContextNodeType per fishd's suggestion.
BUG=15686
TEST=none
Review URL: http://codereview.chromium.org/155954
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@21466 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/renderer_host/render_view_host.cc | 7 | ||||
-rw-r--r-- | chrome/browser/renderer_host/render_view_host.h | 4 | ||||
-rw-r--r-- | chrome/browser/tab_contents/render_view_context_menu.cc | 139 | ||||
-rw-r--r-- | chrome/browser/tab_contents/render_view_context_menu.h | 4 | ||||
-rw-r--r-- | chrome/browser/views/tab_contents/render_view_context_menu_external_win.h | 2 | ||||
-rw-r--r-- | chrome/browser/views/tab_contents/render_view_context_menu_win.h | 2 | ||||
-rw-r--r-- | chrome/common/render_messages.h | 64 | ||||
-rw-r--r-- | chrome/common/render_messages_internal.h | 7 | ||||
-rw-r--r-- | chrome/renderer/render_view.cc | 15 | ||||
-rw-r--r-- | chrome/renderer/render_view.h | 5 |
10 files changed, 202 insertions, 47 deletions
diff --git a/chrome/browser/renderer_host/render_view_host.cc b/chrome/browser/renderer_host/render_view_host.cc index 75b07da..ff99693 100644 --- a/chrome/browser/renderer_host/render_view_host.cc +++ b/chrome/browser/renderer_host/render_view_host.cc @@ -1248,6 +1248,13 @@ void RenderViewHost::OnMsgShowModalHTMLDialog( delegate_->ShowModalHTMLDialog(url, width, height, json_arguments, reply_msg); } +void RenderViewHost::MediaPlayerActionAt(int x, + int y, + const MediaPlayerAction& action) { + // TODO(ajwong): Which thread should run this? Does it matter? + Send(new ViewMsg_MediaPlayerActionAt(routing_id(), x, y, action)); +} + void RenderViewHost::OnMsgPasswordFormsSeen( const std::vector<webkit_glue::PasswordForm>& forms) { delegate_->PasswordFormsSeen(forms); diff --git a/chrome/browser/renderer_host/render_view_host.h b/chrome/browser/renderer_host/render_view_host.h index 6f68bb0..26612b0 100644 --- a/chrome/browser/renderer_host/render_view_host.h +++ b/chrome/browser/renderer_host/render_view_host.h @@ -25,6 +25,7 @@ class SiteInstance; class SkBitmap; class ViewMsg_Navigate; struct ContextMenuParams; +struct MediaPlayerAction; struct ViewHostMsg_DidPrintPage_Params; struct ViewMsg_Navigate_Params; struct WebDropData; @@ -297,6 +298,9 @@ class RenderViewHost : public RenderWidgetHost, void ModalHTMLDialogClosed(IPC::Message* reply_msg, const std::string& json_retval); + // Send an action to the media player element located at |x|, |y|. + void MediaPlayerActionAt(int x, int y, const MediaPlayerAction& action); + // Copies the image at the specified point. void CopyImageAt(int x, int y); diff --git a/chrome/browser/tab_contents/render_view_context_menu.cc b/chrome/browser/tab_contents/render_view_context_menu.cc index e7099ac..1c4959f 100644 --- a/chrome/browser/tab_contents/render_view_context_menu.cc +++ b/chrome/browser/tab_contents/render_view_context_menu.cc @@ -51,44 +51,44 @@ RenderViewContextMenu::~RenderViewContextMenu() { // Menu construction functions ------------------------------------------------- void RenderViewContextMenu::Init() { - InitMenu(params_.node, params_.media_params); + InitMenu(params_.node_type, params_.media_params); DoInit(); } -void RenderViewContextMenu::InitMenu(ContextNode node, +void RenderViewContextMenu::InitMenu(ContextNodeType node_type, ContextMenuMediaParams media_params) { - if (node.type & ContextNode::PAGE) + if (node_type.type & ContextNodeType::PAGE) AppendPageItems(); - if (node.type & ContextNode::FRAME) + if (node_type.type & ContextNodeType::FRAME) AppendFrameItems(); - if (node.type & ContextNode::LINK) + if (node_type.type & ContextNodeType::LINK) AppendLinkItems(); - if (node.type & ContextNode::IMAGE) { - if (node.type & ContextNode::LINK) + if (node_type.type & ContextNodeType::IMAGE) { + if (node_type.type & ContextNodeType::LINK) AppendSeparator(); AppendImageItems(); } - if (node.type & ContextNode::VIDEO) { - if (node.type & ContextNode::LINK) + if (node_type.type & ContextNodeType::VIDEO) { + if (node_type.type & ContextNodeType::LINK) AppendSeparator(); AppendVideoItems(media_params); } - if (node.type & ContextNode::AUDIO) { - if (node.type & ContextNode::LINK) + if (node_type.type & ContextNodeType::AUDIO) { + if (node_type.type & ContextNodeType::LINK) AppendSeparator(); AppendAudioItems(media_params); } - if (node.type & ContextNode::EDITABLE) + if (node_type.type & ContextNodeType::EDITABLE) AppendEditableItems(); - else if (node.type & ContextNode::SELECTION || - node.type & ContextNode::LINK) + else if (node_type.type & ContextNodeType::SELECTION || + node_type.type & ContextNodeType::LINK) AppendCopyItem(); - if (node.type & ContextNode::SELECTION) + if (node_type.type & ContextNodeType::SELECTION) AppendSearchProvider(); AppendSeparator(); AppendDeveloperItems(); @@ -132,23 +132,21 @@ void RenderViewContextMenu::AppendAudioItems( void RenderViewContextMenu::AppendVideoItems( ContextMenuMediaParams media_params) { AppendMediaItems(media_params); - AppendMenuItem(IDS_CONTENT_CONTEXT_FULLSCREEN); AppendSeparator(); AppendMenuItem(IDS_CONTENT_CONTEXT_SAVEVIDEOAS); - AppendMenuItem(IDS_CONTENT_CONTEXT_SAVESCREENSHOTAS); AppendMenuItem(IDS_CONTENT_CONTEXT_COPYVIDEOLOCATION); AppendMenuItem(IDS_CONTENT_CONTEXT_OPENVIDEONEWTAB); } void RenderViewContextMenu::AppendMediaItems( ContextMenuMediaParams media_params) { - if (media_params.player_state & ContextMenuMediaParams::PLAYER_PAUSED) { + if (media_params.player_state & ContextMenuMediaParams::PAUSED) { AppendMenuItem(IDS_CONTENT_CONTEXT_PLAY); } else { AppendMenuItem(IDS_CONTENT_CONTEXT_PAUSE); } - if (media_params.player_state & ContextMenuMediaParams::PLAYER_MUTED) { + if (media_params.player_state & ContextMenuMediaParams::MUTED) { AppendMenuItem(IDS_CONTENT_CONTEXT_UNMUTE); } else { AppendMenuItem(IDS_CONTENT_CONTEXT_MUTE); @@ -350,7 +348,7 @@ bool RenderViewContextMenu::IsItemCommandEnabled(int id) const { case IDS_CONTENT_CONTEXT_PLAYBACKRATE_FASTER: case IDS_CONTENT_CONTEXT_PLAYBACKRATE_DOUBLETIME: return (params_.media_params.player_state & - ContextMenuMediaParams::PLAYER_ERROR) == 0; + ContextMenuMediaParams::IN_ERROR) == 0; case IDS_CONTENT_CONTEXT_SAVESCREENSHOTAS: // TODO(ajwong): Enable save screenshot after we actually implement @@ -365,7 +363,7 @@ bool RenderViewContextMenu::IsItemCommandEnabled(int id) const { case IDS_CONTENT_CONTEXT_SAVEAUDIOAS: case IDS_CONTENT_CONTEXT_SAVEVIDEOAS: return (params_.media_params.player_state & - ContextMenuMediaParams::PLAYER_CAN_SAVE) && + ContextMenuMediaParams::CAN_SAVE) && params_.src_url.is_valid() && URLRequest::IsHandledURL(params_.src_url); @@ -381,25 +379,25 @@ bool RenderViewContextMenu::IsItemCommandEnabled(int id) const { return params_.frame_url.is_valid(); case IDS_CONTENT_CONTEXT_UNDO: - return !!(params_.edit_flags & ContextNode::CAN_UNDO); + return !!(params_.edit_flags & ContextNodeType::CAN_UNDO); case IDS_CONTENT_CONTEXT_REDO: - return !!(params_.edit_flags & ContextNode::CAN_REDO); + return !!(params_.edit_flags & ContextNodeType::CAN_REDO); case IDS_CONTENT_CONTEXT_CUT: - return !!(params_.edit_flags & ContextNode::CAN_CUT); + return !!(params_.edit_flags & ContextNodeType::CAN_CUT); case IDS_CONTENT_CONTEXT_COPY: - return !!(params_.edit_flags & ContextNode::CAN_COPY); + return !!(params_.edit_flags & ContextNodeType::CAN_COPY); case IDS_CONTENT_CONTEXT_PASTE: - return !!(params_.edit_flags & ContextNode::CAN_PASTE); + return !!(params_.edit_flags & ContextNodeType::CAN_PASTE); case IDS_CONTENT_CONTEXT_DELETE: - return !!(params_.edit_flags & ContextNode::CAN_DELETE); + return !!(params_.edit_flags & ContextNodeType::CAN_DELETE); case IDS_CONTENT_CONTEXT_SELECTALL: - return !!(params_.edit_flags & ContextNode::CAN_SELECT_ALL); + return !!(params_.edit_flags & ContextNodeType::CAN_SELECT_ALL); case IDS_CONTENT_CONTEXT_OPENLINKOFFTHERECORD: return !profile_->IsOffTheRecord() && params_.link_url.is_valid(); @@ -456,7 +454,7 @@ bool RenderViewContextMenu::ItemIsChecked(int id) const { // See if the video is set to looping. if (id == IDS_CONTENT_CONTEXT_LOOP) { return (params_.media_params.player_state & - ContextMenuMediaParams::PLAYER_LOOP) != 0; + ContextMenuMediaParams::LOOP) != 0; } // Check box for 'Check the Spelling of this field'. @@ -541,6 +539,82 @@ void RenderViewContextMenu::ExecuteItemCommand(int id) { OpenURL(params_.src_url, NEW_BACKGROUND_TAB, PageTransition::LINK); break; + case IDS_CONTENT_CONTEXT_PLAY: + MediaPlayerActionAt(params_.x, + params_.y, + MediaPlayerAction(MediaPlayerAction::PLAY)); + break; + + case IDS_CONTENT_CONTEXT_PAUSE: + MediaPlayerActionAt(params_.x, + params_.y, + MediaPlayerAction(MediaPlayerAction::PAUSE)); + break; + + case IDS_CONTENT_CONTEXT_MUTE: + MediaPlayerActionAt(params_.x, + params_.y, + MediaPlayerAction(MediaPlayerAction::MUTE)); + break; + + case IDS_CONTENT_CONTEXT_UNMUTE: + MediaPlayerActionAt(params_.x, + params_.y, + MediaPlayerAction(MediaPlayerAction::UNMUTE)); + break; + + case IDS_CONTENT_CONTEXT_LOOP: + if (ItemIsChecked(IDS_CONTENT_CONTEXT_LOOP)) { + MediaPlayerActionAt(params_.x, + params_.y, + MediaPlayerAction(MediaPlayerAction::NO_LOOP)); + } else { + MediaPlayerActionAt(params_.x, + params_.y, + MediaPlayerAction(MediaPlayerAction::LOOP)); + } + break; + + case IDS_CONTENT_CONTEXT_PLAYBACKRATE_SLOW: + MediaPlayerActionAt( + params_.x, + params_.y, + MediaPlayerAction(MediaPlayerAction::SET_PLAYBACK_RATE, + kSlowPlaybackRate)); + break; + + case IDS_CONTENT_CONTEXT_PLAYBACKRATE_NORMAL: + MediaPlayerActionAt( + params_.x, + params_.y, + MediaPlayerAction(MediaPlayerAction::SET_PLAYBACK_RATE, + kNormalPlaybackRate)); + break; + + case IDS_CONTENT_CONTEXT_PLAYBACKRATE_FAST: + MediaPlayerActionAt( + params_.x, + params_.y, + MediaPlayerAction(MediaPlayerAction::SET_PLAYBACK_RATE, + kFastPlaybackRate)); + break; + + case IDS_CONTENT_CONTEXT_PLAYBACKRATE_FASTER: + MediaPlayerActionAt( + params_.x, + params_.y, + MediaPlayerAction(MediaPlayerAction::SET_PLAYBACK_RATE, + kFasterPlaybackRate)); + break; + + case IDS_CONTENT_CONTEXT_PLAYBACKRATE_DOUBLETIME: + MediaPlayerActionAt( + params_.x, + params_.y, + MediaPlayerAction(MediaPlayerAction::SET_PLAYBACK_RATE, + kDoubleTimePlaybackRate)); + break; + case IDS_CONTENT_CONTEXT_BACK: source_tab_contents_->controller().GoBack(); break; @@ -779,3 +853,10 @@ void RenderViewContextMenu::WriteURLToClipboard(const GURL& url) { WriteTextToClipboard(UTF8ToUTF16(utf8_text)); DidWriteURLToClipboard(utf8_text); } + +void RenderViewContextMenu::MediaPlayerActionAt( + int x, + int y, + const MediaPlayerAction& action) { + source_tab_contents_->render_view_host()->MediaPlayerActionAt(x, y, action); +} diff --git a/chrome/browser/tab_contents/render_view_context_menu.h b/chrome/browser/tab_contents/render_view_context_menu.h index afa6861..93c554d 100644 --- a/chrome/browser/tab_contents/render_view_context_menu.h +++ b/chrome/browser/tab_contents/render_view_context_menu.h @@ -25,7 +25,7 @@ class RenderViewContextMenu { void Init(); protected: - void InitMenu(ContextNode node, ContextMenuMediaParams media_params); + void InitMenu(ContextNodeType node, ContextMenuMediaParams media_params); // Functions to be implemented by platform-specific subclasses --------------- @@ -101,6 +101,8 @@ class RenderViewContextMenu { void WriteTextToClipboard(const string16& text); void WriteURLToClipboard(const GURL& url); + void MediaPlayerActionAt(int x, int y, const MediaPlayerAction& action); + bool IsDevCommandEnabled(int id) const; DISALLOW_COPY_AND_ASSIGN(RenderViewContextMenu); diff --git a/chrome/browser/views/tab_contents/render_view_context_menu_external_win.h b/chrome/browser/views/tab_contents/render_view_context_menu_external_win.h index 852adb4..15baa37 100644 --- a/chrome/browser/views/tab_contents/render_view_context_menu_external_win.h +++ b/chrome/browser/views/tab_contents/render_view_context_menu_external_win.h @@ -17,7 +17,7 @@ class RenderViewContextMenuExternalWin : public RenderViewContextMenuWin { const ContextMenuParams& params, const std::vector<int> disabled_menu_ids); - ~RenderViewContextMenuExternalWin() {} + virtual ~RenderViewContextMenuExternalWin() {} protected: // RenderViewContextMenuWin overrides -------------------------------------- diff --git a/chrome/browser/views/tab_contents/render_view_context_menu_win.h b/chrome/browser/views/tab_contents/render_view_context_menu_win.h index 4ff68b9..89560e3 100644 --- a/chrome/browser/views/tab_contents/render_view_context_menu_win.h +++ b/chrome/browser/views/tab_contents/render_view_context_menu_win.h @@ -17,7 +17,7 @@ class RenderViewContextMenuWin : public RenderViewContextMenu, RenderViewContextMenuWin(TabContents* tab_contents, const ContextMenuParams& params); - ~RenderViewContextMenuWin(); + virtual ~RenderViewContextMenuWin(); void RunMenuAt(int x, int y); diff --git a/chrome/common/render_messages.h b/chrome/common/render_messages.h index d3faea0..6835b49 100644 --- a/chrome/common/render_messages.h +++ b/chrome/common/render_messages.h @@ -484,8 +484,8 @@ struct ParamTraits<FilterPolicy::Type> { }; template <> -struct ParamTraits<ContextNode> { - typedef ContextNode param_type; +struct ParamTraits<ContextNodeType> { + typedef ContextNodeType param_type; static void Write(Message* m, const param_type& p) { m->WriteInt(p.type); } @@ -493,7 +493,7 @@ struct ParamTraits<ContextNode> { int type; if (!m->ReadInt(iter, &type)) return false; - *p = ContextNode(type); + *p = ContextNodeType(type); return true; } static void Log(const param_type& p, std::wstring* l) { @@ -503,19 +503,19 @@ struct ParamTraits<ContextNode> { event.append(L"NONE"); } else { event.append(L"("); - if (p.type & ContextNode::PAGE) + if (p.type & ContextNodeType::PAGE) event.append(L"PAGE|"); - if (p.type & ContextNode::FRAME) + if (p.type & ContextNodeType::FRAME) event.append(L"FRAME|"); - if (p.type & ContextNode::LINK) + if (p.type & ContextNodeType::LINK) event.append(L"LINK|"); - if (p.type & ContextNode::IMAGE) + if (p.type & ContextNodeType::IMAGE) event.append(L"IMAGE|"); - if (p.type & ContextNode::SELECTION) + if (p.type & ContextNodeType::SELECTION) event.append(L"SELECTION|"); - if (p.type & ContextNode::EDITABLE) + if (p.type & ContextNodeType::EDITABLE) event.append(L"EDITABLE|"); - if (p.type & ContextNode::MISSPELLED_WORD) + if (p.type & ContextNodeType::MISSPELLED_WORD) event.append(L"MISSPELLED_WORD|"); event.append(L")"); } @@ -838,7 +838,7 @@ template <> struct ParamTraits<ContextMenuParams> { typedef ContextMenuParams param_type; static void Write(Message* m, const param_type& p) { - WriteParam(m, p.node); + WriteParam(m, p.node_type); WriteParam(m, p.x); WriteParam(m, p.y); WriteParam(m, p.link_url); @@ -857,7 +857,7 @@ struct ParamTraits<ContextMenuParams> { } static bool Read(const Message* m, void** iter, param_type* p) { return - ReadParam(m, iter, &p->node) && + ReadParam(m, iter, &p->node_type) && ReadParam(m, iter, &p->x) && ReadParam(m, iter, &p->y) && ReadParam(m, iter, &p->link_url) && @@ -879,6 +879,46 @@ struct ParamTraits<ContextMenuParams> { } }; +template <> +struct ParamTraits<MediaPlayerAction> { + typedef MediaPlayerAction param_type; + static void Write(Message* m, const param_type& p) { + WriteParam(m, p.command); + WriteParam(m, p.playback_rate); + } + static bool Read(const Message* m, void** iter, param_type* p) { + return + ReadParam(m, iter, &p->command) && + ReadParam(m, iter, &p->playback_rate); + } + static void Log(const param_type& p, std::wstring* l) { + std::wstring event = L""; + if (!p.command) { + l->append(L"NONE"); + } else { + l->append(L"("); + if (p.command & MediaPlayerAction::PLAY) + l->append(L"PLAY|"); + if (p.command & MediaPlayerAction::PAUSE) + l->append(L"PAUSE|"); + if (p.command & MediaPlayerAction::MUTE) + l->append(L"MUTE|"); + if (p.command & MediaPlayerAction::UNMUTE) + l->append(L"UNMUTE|"); + if (p.command & MediaPlayerAction::LOOP) + l->append(L"LOOP|"); + if (p.command & MediaPlayerAction::NO_LOOP) + l->append(L"NO_LOOP|"); + if (p.command & MediaPlayerAction::SET_PLAYBACK_RATE) { + l->append(L"SET_PLAYBACK_RATE ["); + LogParam(p.playback_rate, l); + l->append(L"]|"); + } + l->append(L")"); + } + } +}; + // Traits for ViewHostMsg_PaintRect_Params structure to pack/unpack. template <> struct ParamTraits<ViewHostMsg_PaintRect_Params> { diff --git a/chrome/common/render_messages_internal.h b/chrome/common/render_messages_internal.h index 344ebad..f240a34 100644 --- a/chrome/common/render_messages_internal.h +++ b/chrome/common/render_messages_internal.h @@ -65,6 +65,13 @@ IPC_BEGIN_MESSAGES(View) IPC_MESSAGE_ROUTED1(ViewMsg_SetRendererPrefs, RendererPreferences) + // Tells the renderer to perform the given action on the media player + // located at |x|, |y|. + IPC_MESSAGE_ROUTED3(ViewMsg_MediaPlayerActionAt, + int32 /* x */, + int32 /* y */, + MediaPlayerAction) + // Tells the render view to close. IPC_MESSAGE_ROUTED0(ViewMsg_Close) diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc index fd8f61a..6af62ef 100644 --- a/chrome/renderer/render_view.cc +++ b/chrome/renderer/render_view.cc @@ -59,6 +59,7 @@ #include "webkit/api/public/WebDragData.h" #include "webkit/api/public/WebForm.h" #include "webkit/api/public/WebHistoryItem.h" +#include "webkit/api/public/WebNode.h" #include "webkit/api/public/WebPoint.h" #include "webkit/api/public/WebRect.h" #include "webkit/api/public/WebScriptSource.h" @@ -423,6 +424,7 @@ void RenderView::OnMessageReceived(const IPC::Message& message) { IPC_MESSAGE_HANDLER(ViewMsg_EnableIntrinsicWidthChangedMode, OnEnableIntrinsicWidthChangedMode) IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs) + IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt) IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive) // Have the super handle all other messages. @@ -1977,7 +1979,7 @@ void RenderView::SyncNavigationState() { } void RenderView::ShowContextMenu(WebView* webview, - ContextNode node, + ContextNodeType node_type, int x, int y, const GURL& link_url, @@ -1991,7 +1993,7 @@ void RenderView::ShowContextMenu(WebView* webview, const std::string& security_info, const std::string& frame_charset) { ContextMenuParams params; - params.node = node; + params.node_type = node_type; params.x = x; params.y = y; params.src_url = src_url; @@ -2635,6 +2637,15 @@ void RenderView::OnSetRendererPrefs(const RendererPreferences& renderer_prefs) { // and |subpixel_rendering| through to Skia. } +void RenderView::OnMediaPlayerActionAt(int x, + int y, + const MediaPlayerAction& action) { + if (!webview()) + return; + + webview()->MediaPlayerActionAt(x, y, action); +} + void RenderView::OnUpdateBackForwardListCount(int back_list_count, int forward_list_count) { history_back_list_count_ = back_list_count; diff --git a/chrome/renderer/render_view.h b/chrome/renderer/render_view.h index d83bab9..d4214c0 100644 --- a/chrome/renderer/render_view.h +++ b/chrome/renderer/render_view.h @@ -262,7 +262,7 @@ class RenderView : public RenderWidget, ErrorPageType error_type); virtual void ShowContextMenu(WebView* webview, - ContextNode node, + ContextNodeType node_type, int x, int y, const GURL& link_url, @@ -531,6 +531,9 @@ class RenderView : public RenderWidget, void OnEnableViewSourceMode(); void OnEnableIntrinsicWidthChangedMode(); void OnSetRendererPrefs(const RendererPreferences& renderer_prefs); + void OnMediaPlayerActionAt(int x, + int y, + const MediaPlayerAction& action); void OnUpdateBackForwardListCount(int back_list_count, int forward_list_count); void OnGetAccessibilityInfo( |