summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorserya@google.com <serya@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-27 10:11:40 +0000
committerserya@google.com <serya@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-27 10:11:40 +0000
commitce9802042c9b9ff0bd4e60b017333ff5735201b2 (patch)
tree6914a3c7fb6fa398fddb0096dc9db62d7d4d632c
parent60a1d495e24ed67cd9c1559395d183cd8a85504f (diff)
downloadchromium_src-ce9802042c9b9ff0bd4e60b017333ff5735201b2.zip
chromium_src-ce9802042c9b9ff0bd4e60b017333ff5735201b2.tar.gz
chromium_src-ce9802042c9b9ff0bd4e60b017333ff5735201b2.tar.bz2
Moving mediaplayer to the chrome filebrowser. Observable behaviour should not change.
BUG=chromium-os:14880 TEST=Click "play" button on an audion file in the file browser. Check that the mediaplayer panel has popped up. Click on another file. Check that the mediaplayer playlist panel has popped up and contains 2 items. Review URL: http://codereview.chromium.org/7067020 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@87002 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/app/generated_resources.grd3
-rw-r--r--chrome/browser/browser_resources.grd2
-rw-r--r--chrome/browser/chromeos/extensions/media_player_event_router.cc29
-rw-r--r--chrome/browser/chromeos/extensions/media_player_event_router.h31
-rw-r--r--chrome/browser/chromeos/media/media_player.cc311
-rw-r--r--chrome/browser/chromeos/media/media_player.h (renamed from chrome/browser/ui/webui/mediaplayer_ui.h)98
-rw-r--r--chrome/browser/chromeos/media/media_player_browsertest.cc (renamed from chrome/browser/ui/webui/mediaplayer_browsertest.cc)39
-rw-r--r--chrome/browser/extensions/extension_file_browser_private_api.cc2
-rw-r--r--chrome/browser/extensions/extension_function_dispatcher.cc7
-rw-r--r--chrome/browser/extensions/extension_mediaplayer_private_api.cc76
-rw-r--r--chrome/browser/extensions/extension_mediaplayer_private_api.h57
-rw-r--r--chrome/browser/extensions/extension_service.cc2
-rw-r--r--chrome/browser/extensions/file_manager_util.cc51
-rw-r--r--chrome/browser/extensions/file_manager_util.h3
-rw-r--r--chrome/browser/resources/component_extension_resources.grd2
-rw-r--r--chrome/browser/resources/file_manager/js/file_manager.js7
-rw-r--r--chrome/browser/resources/file_manager/manifest.json1
-rw-r--r--chrome/browser/resources/file_manager/mediaplayer.html (renamed from chrome/browser/resources/mediaplayer.html)98
-rw-r--r--chrome/browser/resources/file_manager/playlist.html (renamed from chrome/browser/resources/playlist.html)15
-rw-r--r--chrome/browser/ui/browser_init.cc1
-rw-r--r--chrome/browser/ui/webui/active_downloads_ui.cc2
-rw-r--r--chrome/browser/ui/webui/chrome_web_ui_factory.cc3
-rw-r--r--chrome/browser/ui/webui/mediaplayer_ui.cc624
-rw-r--r--chrome/chrome_browser.gypi11
-rw-r--r--chrome/chrome_tests.gypi4
-rw-r--r--chrome/common/extensions/api/extension_api.json104
-rw-r--r--chrome/common/extensions/extension.cc3
-rw-r--r--chrome/common/extensions/extension.h1
-rw-r--r--chrome/common/extensions/extension_unittest.cc1
-rw-r--r--chrome/renderer/resources/renderer_extension_bindings.js1
-rw-r--r--webkit/chromeos/fileapi/cros_mount_point_provider.cc14
-rw-r--r--webkit/chromeos/fileapi/cros_mount_point_provider.h2
-rw-r--r--webkit/fileapi/file_system_mount_point_provider.h6
33 files changed, 799 insertions, 812 deletions
diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd
index 44d462f..18492f9 100644
--- a/chrome/app/generated_resources.grd
+++ b/chrome/app/generated_resources.grd
@@ -8627,6 +8627,9 @@ Keep your key file in a safe place. You will need it to create new versions of y
<message name="IDS_FILE_BROWSER_MANY_FILES_SELECTED" desc="Many files selected.">
$1 files selected, $2
</message>
+ <message name="IDS_FILE_BROWSER_PLAYBACK_ERROR" desc="Error playing back.">
+ Error playing back
+ </message>
<!-- Bookmark manager -->
<message name="IDS_BOOKMARK_MANAGER_TITLE" desc="Title of the bookmark manager window.">
diff --git a/chrome/browser/browser_resources.grd b/chrome/browser/browser_resources.grd
index 029b12b..e54e41e 100644
--- a/chrome/browser/browser_resources.grd
+++ b/chrome/browser/browser_resources.grd
@@ -95,8 +95,6 @@
<include name="IDR_KEYBOARD_OVERLAY_DATA_JS" file="resources\keyboard_overlay_data.js" flattenhtml="true" type="BINDATA" />
<include name="IDR_KEYBOARD_OVERLAY_HTML" file="resources\keyboard_overlay.html" flattenhtml="true" type="BINDATA" />
<include name="IDR_KEYBOARD_OVERLAY_JS" file="resources\keyboard_overlay.js" flattenhtml="true" type="BINDATA" />
- <include name="IDR_MEDIAPLAYER_HTML" file="resources\mediaplayer.html" flattenhtml="true" type="BINDATA" />
- <include name="IDR_MEDIAPLAYERPLAYLIST_HTML" file="resources\playlist.html" flattenhtml="true" type="BINDATA" />
<include name="IDR_MOBILE_SETUP_PAGE_HTML" file="resources\mobile_setup.html" flattenhtml="true" type="BINDATA" />
<include name="IDR_NOTIFICATION_ICON_LINK_HTML" file="resources\notification_icon_link.html" type="BINDATA" />
<include name="IDR_OFFLINE_LOAD_HTML" file="resources\offline_load.html" flattenhtml="true" type="BINDATA" />
diff --git a/chrome/browser/chromeos/extensions/media_player_event_router.cc b/chrome/browser/chromeos/extensions/media_player_event_router.cc
new file mode 100644
index 0000000..ea8f70b
--- /dev/null
+++ b/chrome/browser/chromeos/extensions/media_player_event_router.cc
@@ -0,0 +1,29 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/chromeos/extensions/media_player_event_router.h"
+
+#include "base/memory/singleton.h"
+#include "chrome/browser/extensions/extension_event_router.h"
+#include "chrome/browser/profiles/profile.h"
+
+ExtensionMediaPlayerEventRouter::ExtensionMediaPlayerEventRouter()
+ : profile_(NULL) {
+}
+
+ExtensionMediaPlayerEventRouter*
+ ExtensionMediaPlayerEventRouter::GetInstance() {
+ return Singleton<ExtensionMediaPlayerEventRouter>::get();
+}
+
+void ExtensionMediaPlayerEventRouter::Init(Profile* profile) {
+ profile_ = profile;
+}
+
+void ExtensionMediaPlayerEventRouter::NotifyPlaylistChanged() {
+ if (profile_ && profile_->GetExtensionEventRouter()) {
+ profile_->GetExtensionEventRouter()->DispatchEventToRenderers(
+ "mediaPlayerPrivate.onPlaylistChanged", "[]", NULL, GURL());
+ }
+}
diff --git a/chrome/browser/chromeos/extensions/media_player_event_router.h b/chrome/browser/chromeos/extensions/media_player_event_router.h
new file mode 100644
index 0000000..5095de1
--- /dev/null
+++ b/chrome/browser/chromeos/extensions/media_player_event_router.h
@@ -0,0 +1,31 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_CHROMEOS_EXTENSIONS_MEDIA_PLAYER_EVENT_ROUTER_H_
+#define CHROME_BROWSER_CHROMEOS_EXTENSIONS_MEDIA_PLAYER_EVENT_ROUTER_H_
+#pragma once
+
+#include "base/basictypes.h"
+
+class Profile;
+template <typename T> struct DefaultSingletonTraits;
+
+// Event router class for events related to Mediaplayer.
+class ExtensionMediaPlayerEventRouter {
+ public:
+ static ExtensionMediaPlayerEventRouter* GetInstance();
+
+ void Init(Profile* profile);
+
+ void NotifyPlaylistChanged();
+
+ private:
+ Profile* profile_;
+
+ ExtensionMediaPlayerEventRouter();
+ friend struct DefaultSingletonTraits<ExtensionMediaPlayerEventRouter>;
+ DISALLOW_COPY_AND_ASSIGN(ExtensionMediaPlayerEventRouter);
+};
+
+#endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_MEDIA_PLAYER_EVENT_ROUTER_H_
diff --git a/chrome/browser/chromeos/media/media_player.cc b/chrome/browser/chromeos/media/media_player.cc
new file mode 100644
index 0000000..d320cfa
--- /dev/null
+++ b/chrome/browser/chromeos/media/media_player.cc
@@ -0,0 +1,311 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/chromeos/media/media_player.h"
+
+#include "base/command_line.h"
+#include "base/logging.h"
+#include "base/memory/singleton.h"
+#include "base/memory/weak_ptr.h"
+#include "base/message_loop.h"
+#include "base/path_service.h"
+#include "base/string_piece.h"
+#include "base/string_util.h"
+#include "base/threading/thread.h"
+#include "base/time.h"
+#include "base/values.h"
+#include "chrome/browser/bookmarks/bookmark_model.h"
+#include "chrome/browser/chromeos/extensions/media_player_event_router.h"
+#include "chrome/browser/download/download_manager.h"
+#include "chrome/browser/download/download_util.h"
+#include "chrome/browser/extensions/file_manager_util.h"
+#include "chrome/browser/history/history_types.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/tabs/tab_strip_model.h"
+#include "chrome/browser/ui/browser.h"
+#include "chrome/browser/ui/browser_list.h"
+#include "chrome/browser/ui/browser_window.h"
+#include "chrome/browser/ui/webui/favicon_source.h"
+#include "chrome/common/chrome_paths.h"
+#include "chrome/common/chrome_switches.h"
+#include "chrome/common/jstemplate_builder.h"
+#include "chrome/common/net/url_fetcher.h"
+#include "chrome/common/time_format.h"
+#include "chrome/common/url_constants.h"
+#include "content/browser/browser_thread.h"
+#include "content/browser/tab_contents/tab_contents.h"
+#include "content/browser/user_metrics.h"
+#include "grit/browser_resources.h"
+#include "grit/chromium_strings.h"
+#include "grit/generated_resources.h"
+#include "grit/locale_settings.h"
+#include "net/base/escape.h"
+#include "net/base/load_flags.h"
+#include "net/url_request/url_request_job.h"
+#include "ui/base/resource/resource_bundle.h"
+
+#if defined(OS_CHROMEOS)
+#include "chrome/browser/chromeos/frame/panel_browser_view.h"
+#endif
+
+static const char* kMediaPlayerAppName = "mediaplayer";
+static const int kPopupLeft = 0;
+static const int kPopupTop = 0;
+static const int kPopupWidth = 350;
+static const int kPopupHeight = 300;
+
+const MediaPlayer::UrlVector& MediaPlayer::GetPlaylist() const {
+ return current_playlist_;
+}
+
+int MediaPlayer::GetPlaylistPosition() const {
+ return current_position_;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+//
+// Mediaplayer
+//
+////////////////////////////////////////////////////////////////////////////////
+
+// Allows InvokeLater without adding refcounting. This class is a Singleton and
+// won't be deleted until it's last InvokeLater is run.
+DISABLE_RUNNABLE_METHOD_REFCOUNT(MediaPlayer);
+
+MediaPlayer::~MediaPlayer() {
+}
+
+// static
+MediaPlayer* MediaPlayer::GetInstance() {
+ return Singleton<MediaPlayer>::get();
+}
+
+void MediaPlayer::EnqueueMediaFile(Profile* profile, const FilePath& file_path,
+ Browser* creator) {
+ GURL url;
+ if (!FileManagerUtil::ConvertFileToFileSystemUrl(profile, file_path,
+ GetOriginUrl(), &url)) {
+ }
+ EnqueueMediaFileUrl(url, creator);
+}
+
+void MediaPlayer::EnqueueMediaFileUrl(const GURL& url, Browser* creator) {
+ if (mediaplayer_browser_ == NULL) {
+ PopupMediaPlayer(creator);
+ }
+ EnqueueMediaFileUrl(url);
+}
+
+void MediaPlayer::EnqueueMediaFileUrl(const GURL& url) {
+ current_playlist_.push_back(MediaUrl(url));
+ NotifyPlaylistChanged();
+}
+
+void MediaPlayer::ForcePlayMediaFile(Profile* profile,
+ const FilePath& file_path,
+ Browser* creator) {
+ GURL url;
+ if (!FileManagerUtil::ConvertFileToFileSystemUrl(profile, file_path,
+ GetOriginUrl(), &url)) {
+ return;
+ }
+ ForcePlayMediaURL(url, creator);
+}
+
+void MediaPlayer::ForcePlayMediaURL(const GURL& url, Browser* creator) {
+ if (mediaplayer_browser_ == NULL) {
+ PopupMediaPlayer(creator);
+ }
+ current_playlist_.push_back(MediaUrl(url));
+ current_position_ = current_playlist_.size() - 1;
+ pending_playback_request_ = true;
+ NotifyPlaylistChanged();
+}
+
+void MediaPlayer::TogglePlaylistWindowVisible() {
+ if (playlist_browser_) {
+ ClosePlaylistWindow();
+ } else {
+ ShowPlaylistWindow();
+ }
+}
+
+void MediaPlayer::ShowPlaylistWindow() {
+ if (playlist_browser_ == NULL) {
+ PopupPlaylist(NULL);
+ }
+}
+
+void MediaPlayer::ClosePlaylistWindow() {
+ if (playlist_browser_ != NULL) {
+ playlist_browser_->window()->Close();
+ }
+}
+
+void MediaPlayer::SetPlaylistPosition(int position) {
+ const int playlist_size = current_playlist_.size();
+ if (current_position_ < 0 || current_position_ > playlist_size)
+ position = current_playlist_.size();
+ if (current_position_ != position) {
+ current_position_ = position;
+ NotifyPlaylistChanged();
+ }
+}
+
+void MediaPlayer::SetPlaybackError(GURL const& url) {
+ for (size_t x = 0; x < current_playlist_.size(); x++) {
+ if (current_playlist_[x].url == url) {
+ current_playlist_[x].haderror = true;
+ }
+ }
+ NotifyPlaylistChanged();
+}
+
+void MediaPlayer::Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details) {
+ DCHECK(type == NotificationType::BROWSER_CLOSING);
+ registrar_.Remove(this,
+ NotificationType::BROWSER_CLOSING,
+ source);
+ if (Source<Browser>(source).ptr() == mediaplayer_browser_) {
+ mediaplayer_browser_ = NULL;
+ } else if (Source<Browser>(source).ptr() == playlist_browser_) {
+ playlist_browser_ = NULL;
+ }
+}
+
+void MediaPlayer::NotifyPlaylistChanged() {
+ ExtensionMediaPlayerEventRouter::GetInstance()->NotifyPlaylistChanged();
+}
+
+bool MediaPlayer::GetPendingPlayRequestAndReset() {
+ bool result = pending_playback_request_;
+ pending_playback_request_ = false;
+ return result;
+}
+
+void MediaPlayer::SetPlaybackRequest() {
+ pending_playback_request_ = true;
+}
+
+void MediaPlayer::ToggleFullscreen() {
+ if (mediaplayer_browser_) {
+ mediaplayer_browser_->ToggleFullscreenMode();
+ }
+}
+
+void MediaPlayer::PopupPlaylist(Browser* creator) {
+ Profile* profile = BrowserList::GetLastActive()->profile();
+ playlist_browser_ = Browser::CreateForApp(Browser::TYPE_PANEL,
+ kMediaPlayerAppName,
+ gfx::Size(),
+ profile);
+ registrar_.Add(this,
+ NotificationType::BROWSER_CLOSING,
+ Source<Browser>(playlist_browser_));
+ playlist_browser_->AddSelectedTabWithURL(GetMediaplayerPlaylistUrl(),
+ PageTransition::LINK);
+ playlist_browser_->window()->SetBounds(gfx::Rect(kPopupLeft,
+ kPopupTop,
+ kPopupWidth,
+ kPopupHeight));
+ playlist_browser_->window()->Show();
+}
+
+void MediaPlayer::PopupMediaPlayer(Browser* creator) {
+ if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ NewRunnableMethod(this, &MediaPlayer::PopupMediaPlayer,
+ static_cast<Browser*>(NULL)));
+ return;
+ }
+ Profile* profile = BrowserList::GetLastActive()->profile();
+ mediaplayer_browser_ = Browser::CreateForApp(Browser::TYPE_PANEL,
+ kMediaPlayerAppName,
+ gfx::Size(),
+ profile);
+ registrar_.Add(this,
+ NotificationType::BROWSER_CLOSING,
+ Source<Browser>(mediaplayer_browser_));
+
+#if defined(OS_CHROMEOS)
+ // Since we are on chromeos, popups should be a PanelBrowserView,
+ // so we can just cast it.
+ if (creator) {
+ chromeos::PanelBrowserView* creatorview =
+ static_cast<chromeos::PanelBrowserView*>(creator->window());
+ chromeos::PanelBrowserView* view =
+ static_cast<chromeos::PanelBrowserView*>(
+ mediaplayer_browser_->window());
+ view->SetCreatorView(creatorview);
+ }
+#endif
+ mediaplayer_browser_->AddSelectedTabWithURL(GetMediaPlayerUrl(),
+ PageTransition::LINK);
+ mediaplayer_browser_->window()->SetBounds(gfx::Rect(kPopupLeft,
+ kPopupTop,
+ kPopupWidth,
+ kPopupHeight));
+ mediaplayer_browser_->window()->Show();
+}
+
+net::URLRequestJob* MediaPlayer::MaybeIntercept(net::URLRequest* request) {
+ // Don't attempt to intercept here as we want to wait until the mime
+ // type is fully determined.
+ return NULL;
+}
+
+// This is the list of mime types currently supported by the Google
+// Document Viewer.
+static const char* const supported_mime_type_list[] = {
+ "audio/mpeg",
+ "video/mp4",
+ "audio/mp3"
+};
+
+net::URLRequestJob* MediaPlayer::MaybeInterceptResponse(
+ net::URLRequest* request) {
+ // Do not intercept this request if it is a download.
+ if (request->load_flags() & net::LOAD_IS_DOWNLOAD) {
+ return NULL;
+ }
+
+ std::string mime_type;
+ request->GetMimeType(&mime_type);
+ // If it is in our list of known URLs, enqueue the url then
+ // Cancel the request so the mediaplayer can handle it when
+ // it hits it in the playlist.
+ if (supported_mime_types_.find(mime_type) != supported_mime_types_.end()) {
+ if (request->referrer() != chrome::kChromeUIMediaplayerURL &&
+ !request->referrer().empty()) {
+ EnqueueMediaFileUrl(request->url(), NULL);
+ request->Cancel();
+ }
+ }
+ return NULL;
+}
+
+GURL MediaPlayer::GetOriginUrl() const {
+ return FileManagerUtil::GetMediaPlayerUrl().GetOrigin();
+}
+
+GURL MediaPlayer::GetMediaplayerPlaylistUrl() const {
+ return FileManagerUtil::GetMediaPlayerPlaylistUrl();
+}
+
+GURL MediaPlayer::GetMediaPlayerUrl() const {
+ return FileManagerUtil::GetMediaPlayerUrl();
+}
+
+MediaPlayer::MediaPlayer()
+ : current_position_(0),
+ pending_playback_request_(false),
+ playlist_browser_(NULL),
+ mediaplayer_browser_(NULL) {
+ for (size_t i = 0; i < arraysize(supported_mime_type_list); ++i) {
+ supported_mime_types_.insert(supported_mime_type_list[i]);
+ }
+};
diff --git a/chrome/browser/ui/webui/mediaplayer_ui.h b/chrome/browser/chromeos/media/media_player.h
index 7e25ba5..e916ea2 100644
--- a/chrome/browser/ui/webui/mediaplayer_ui.h
+++ b/chrome/browser/chromeos/media/media_player.h
@@ -2,32 +2,33 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef CHROME_BROWSER_UI_WEBUI_MEDIAPLAYER_UI_H_
-#define CHROME_BROWSER_UI_WEBUI_MEDIAPLAYER_UI_H_
+#ifndef CHROME_BROWSER_CHROMEOS_MEDIA_MEDIA_PLAYER_H_
+#define CHROME_BROWSER_CHROMEOS_MEDIA_MEDIA_PLAYER_H_
#pragma once
#include <set>
#include <vector>
-#include "chrome/browser/ui/webui/chrome_url_data_manager.h"
-#include "content/browser/webui/web_ui.h"
+#include "base/memory/singleton.h"
#include "content/common/notification_observer.h"
#include "content/common/notification_registrar.h"
#include "content/common/notification_source.h"
#include "content/common/notification_type.h"
-#include "net/base/directory_lister.h"
+
#include "net/url_request/url_request.h"
template <typename T> struct DefaultSingletonTraits;
class Browser;
class GURL;
-class MediaplayerHandler;
class Profile;
class MediaPlayer : public NotificationObserver,
public net::URLRequest::Interceptor {
public:
+ struct MediaUrl;
+ typedef std::vector<MediaUrl> UrlVector;
+
virtual ~MediaPlayer();
// Enqueues this file into the current playlist. If the mediaplayer is
@@ -61,30 +62,29 @@ class MediaPlayer : public NotificationObserver,
// Force the playlist window to be closed.
void ClosePlaylistWindow();
- // Sets the currently playing element to the given offset.
- void SetPlaylistOffset(int offset);
+ // Sets the currently playing element to the given positions.
+ void SetPlaylistPosition(int position);
- // Set a new playback handler to give events to, along with the
- // tab contents of the page which holds the mediaplayer. it is expected
- // That only one of these will exist at any given time.
- void SetNewHandler(MediaplayerHandler* handler,
- TabContents* contents);
+ // Returns current playlist.
+ const UrlVector& GetPlaylist() const;
- // Removes the handler.
- void RemoveHandler(MediaplayerHandler* handler);
+ // Returns current playlist position.
+ int GetPlaylistPosition() const;
- // Registers a new playlist handler which receives events from the
- // mediaplayer, along with the tab contents which has the playlist in it.
- void RegisterNewPlaylistHandler(MediaplayerHandler* handler,
- TabContents* contents);
+ // Set flag that error occuires while playing the url.
+ void SetPlaybackError(GURL const& url);
- // Removes the playlist handler.
- void RemovePlaylistHandler(MediaplayerHandler* handler);
-
- // Notfiys the mediaplayer that the playlist changed. This could be
+ // Notfies the mediaplayer that the playlist changed. This could be
// called from the mediaplayer itself for example.
void NotifyPlaylistChanged();
+ // Retuen true if playback requested. Resets this flag.
+ bool GetPendingPlayRequestAndReset();
+
+ // Requests starting playback of the current playlist item when the
+ // mediaplayer get the playlist updated.
+ void SetPlaybackRequest();
+
// Always returns NULL because we don't want to attempt a redirect
// before seeing the detected mime type of the request.
// Implementation of net::URLRequest::Interceptor.
@@ -107,8 +107,19 @@ class MediaPlayer : public NotificationObserver,
private:
friend struct DefaultSingletonTraits<MediaPlayer>;
+ // The current playlist of urls.
+ UrlVector current_playlist_;
+ // The position into the current_playlist_ of the currently playing item.
+ int current_position_;
+
+ bool pending_playback_request_;
+
MediaPlayer();
+ GURL GetOriginUrl() const;
+ GURL GetMediaplayerPlaylistUrl() const;
+ GURL GetMediaPlayerUrl() const;
+
// Popup the mediaplayer, this shows the browser, and sets up its
// locations correctly.
void PopupMediaPlayer(Browser* creator);
@@ -117,16 +128,7 @@ class MediaPlayer : public NotificationObserver,
// chrome://mediaplayer#playlist
void PopupPlaylist(Browser* creator);
- // Registers the listeners for the close events on the browser windows.
- void RegisterListeners();
-
- // Set when the register handler is called. When the media player is
- // closed, this pointer is set back to NULL.
- MediaplayerHandler* handler_;
-
- // Set when the register playlist handler is called. When the playlist
- // is closed, this pointer is set back to NULL.
- MediaplayerHandler* playlist_;
+ void EnqueueMediaFileUrl(const GURL& url);
// Browser containing the playlist. Used to force closes. This is created
// By the PopupPlaylist call, and is NULLed out when the window is closed.
@@ -137,35 +139,23 @@ class MediaPlayer : public NotificationObserver,
// is closed.
Browser* mediaplayer_browser_;
- // List of URLs that were enqueued during the time that the mediaplayer
- // had not poped up yet. This is claered out after the mediaplayer pops up.
- std::vector<GURL> unhandled_urls_;
-
// Used to register for events on the windows, like to listen for closes.
NotificationRegistrar registrar_;
- // Tab contents of the mediaplayer. Used to listen for events
- // which would cause the mediaplayer to be closed. These are cleared out
- // when the mediaplayer is closed.
- TabContents* mediaplayer_tab_;
-
- // Tab contents of the playlist tab. used to listen for events which would
- // cause the mediaplayer to be closed. These are cleared out when the
- // playlist is closed.
- TabContents* playlist_tab_;
-
// List of mimetypes that the mediaplayer should listen to. Used for
// interceptions of url GETs.
std::set<std::string> supported_mime_types_;
+ friend class MediaPlayerBrowserTest;
DISALLOW_COPY_AND_ASSIGN(MediaPlayer);
};
-class MediaplayerUI : public WebUI {
- public:
- explicit MediaplayerUI(TabContents* contents);
-
- private:
- DISALLOW_COPY_AND_ASSIGN(MediaplayerUI);
+struct MediaPlayer::MediaUrl {
+ MediaUrl() {}
+ explicit MediaUrl(const GURL& newurl)
+ : url(newurl),
+ haderror(false) {}
+ GURL url;
+ bool haderror;
};
-#endif // CHROME_BROWSER_UI_WEBUI_MEDIAPLAYER_UI_H_
+#endif // CHROME_BROWSER_CHROMEOS_MEDIA_MEDIA_PLAYER_H_
diff --git a/chrome/browser/ui/webui/mediaplayer_browsertest.cc b/chrome/browser/chromeos/media/media_player_browsertest.cc
index 2bd67e4..9afaff3 100644
--- a/chrome/browser/ui/webui/mediaplayer_browsertest.cc
+++ b/chrome/browser/chromeos/media/media_player_browsertest.cc
@@ -5,9 +5,9 @@
#include "base/command_line.h"
#include "base/memory/ref_counted.h"
#include "base/utf_string_conversions.h"
+#include "chrome/browser/chromeos/media/media_player.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_list.h"
-#include "chrome/browser/ui/webui/mediaplayer_ui.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/url_constants.h"
#include "chrome/test/automation/dom_element_proxy.h"
@@ -15,8 +15,6 @@
#include "chrome/test/ui_test_utils.h"
#include "content/browser/tab_contents/tab_contents.h"
-namespace {
-
class MediaPlayerBrowserTest : public InProcessBrowserTest {
public:
MediaPlayerBrowserTest() {}
@@ -25,37 +23,23 @@ class MediaPlayerBrowserTest : public InProcessBrowserTest {
return GURL("http://localhost:1337/files/plugin/sample_mp3.mp3");
}
- bool IsPlayerVisible() {
+ bool IsBrowserVisible(Browser* browser) {
+ if (browser == NULL)
+ return false;
for (BrowserList::const_iterator it = BrowserList::begin();
it != BrowserList::end(); ++it) {
- if ((*it)->is_type_panel() && (*it)->is_app()) {
- const GURL& url =
- (*it)->GetTabContentsAt((*it)->active_index())->GetURL();
-
- if (url.SchemeIs(chrome::kChromeUIScheme) &&
- url.host() == chrome::kChromeUIMediaplayerHost) {
- return true;
- }
- }
+ if ((*it)->is_type_panel() && (*it)->is_app() && (*it) == browser)
+ return true;
}
return false;
}
+ bool IsPlayerVisible() {
+ return IsBrowserVisible(MediaPlayer::GetInstance()->mediaplayer_browser_);
+ }
+
bool IsPlaylistVisible() {
- for (BrowserList::const_iterator it = BrowserList::begin();
- it != BrowserList::end(); ++it) {
- if ((*it)->is_type_panel() && (*it)->is_app()) {
- const GURL& url =
- (*it)->GetTabContentsAt((*it)->active_index())->GetURL();
-
- if (url.SchemeIs(chrome::kChromeUIScheme) &&
- url.host() == chrome::kChromeUIMediaplayerHost &&
- url.ref() == "playlist") {
- return true;
- }
- }
- }
- return false;
+ return IsBrowserVisible(MediaPlayer::GetInstance()->playlist_browser_);
}
};
@@ -92,4 +76,3 @@ IN_PROC_BROWSER_TEST_F(MediaPlayerBrowserTest, PopupPlaylist) {
EXPECT_TRUE(IsPlaylistVisible());
}
-} // namespace
diff --git a/chrome/browser/extensions/extension_file_browser_private_api.cc b/chrome/browser/extensions/extension_file_browser_private_api.cc
index 9d53ce3..9896400 100644
--- a/chrome/browser/extensions/extension_file_browser_private_api.cc
+++ b/chrome/browser/extensions/extension_file_browser_private_api.cc
@@ -1074,6 +1074,8 @@ bool FileDialogStringsFunction::RunImpl() {
SET_STRING(IDS_FILE_BROWSER, ONE_FILE_SELECTED);
SET_STRING(IDS_FILE_BROWSER, MANY_FILES_SELECTED);
+ SET_STRING(IDS_FILE_BROWSER, PLAYBACK_ERROR);
+
// FILEBROWSER, without the underscore, is from the old school codebase.
// TODO(rginda): Move these into IDS_FILE_BROWSER post M12.
SET_STRING(IDS_FILEBROWSER, CONFIRM_DELETE);
diff --git a/chrome/browser/extensions/extension_function_dispatcher.cc b/chrome/browser/extensions/extension_function_dispatcher.cc
index a19b839..a012faa 100644
--- a/chrome/browser/extensions/extension_function_dispatcher.cc
+++ b/chrome/browser/extensions/extension_function_dispatcher.cc
@@ -67,6 +67,7 @@
#if defined(OS_CHROMEOS)
#include "chrome/browser/extensions/extension_file_browser_private_api.h"
#include "chrome/browser/extensions/extension_info_private_api_chromeos.h"
+#include "chrome/browser/extensions/extension_mediaplayer_private_api.h"
#endif
// FactoryRegistry -------------------------------------------------------------
@@ -335,6 +336,12 @@ void FactoryRegistry::ResetFunctions() {
RegisterFunction<SelectFilesFunction>();
RegisterFunction<ViewFilesFunction>();
+ // Mediaplayer
+ RegisterFunction<PlayAtMediaplayerFunction>();
+ RegisterFunction<SetPlaybackErrorMediaplayerFunction>();
+ RegisterFunction<GetPlaylistMediaplayerFunction>();
+ RegisterFunction<TogglePlaylistPanelMediaplayerFunction>();
+ RegisterFunction<ToggleFullscreenMediaplayerFunction>();
#if defined(TOUCH_UI)
// Input
RegisterFunction<SendHandwritingStrokeFunction>();
diff --git a/chrome/browser/extensions/extension_mediaplayer_private_api.cc b/chrome/browser/extensions/extension_mediaplayer_private_api.cc
new file mode 100644
index 0000000..4fdee72
--- /dev/null
+++ b/chrome/browser/extensions/extension_mediaplayer_private_api.cc
@@ -0,0 +1,76 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/extensions/extension_mediaplayer_private_api.h"
+
+#include "base/values.h"
+#include "chrome/browser/chromeos/media/media_player.h"
+
+static const char kPropertyPath[] = "path";
+static const char kPropertyForce[] = "force";
+static const char kPropertyItems[] = "items";
+static const char kPropertyPosition[] = "position";
+static const char kPropertyError[] = "error";
+static const char kPropertyPendingPlaybackRequest[] =
+ "pendingPlaybackRequest";
+
+bool PlayAtMediaplayerFunction::RunImpl() {
+ int position;
+ if (!args_->GetInteger(0, &position))
+ return false;
+ MediaPlayer::GetInstance()->SetPlaybackRequest();
+ MediaPlayer::GetInstance()->SetPlaylistPosition(position);
+ return true;
+}
+
+static ListValue* GetPlaylistItems() {
+ ListValue* result = new ListValue();
+
+ MediaPlayer::UrlVector const& src = MediaPlayer::GetInstance()->GetPlaylist();
+
+ for (size_t i = 0; i < src.size(); i++) {
+ DictionaryValue* url_value = new DictionaryValue();
+ url_value->SetString(kPropertyPath, src[i].url.spec());
+ url_value->SetBoolean(kPropertyError, src[i].haderror);
+ result->Append(url_value);
+ }
+ return result;
+}
+
+bool GetPlaylistMediaplayerFunction::RunImpl() {
+ bool reset_pending_playback_request;
+ if (!args_->GetBoolean(0, &reset_pending_playback_request))
+ return false;
+
+ DictionaryValue* result = new DictionaryValue();
+ MediaPlayer* player = MediaPlayer::GetInstance();
+
+ result->Set(kPropertyItems, GetPlaylistItems());
+ result->SetInteger(kPropertyPosition, player->GetPlaylistPosition());
+ if (reset_pending_playback_request) {
+ result->SetBoolean(kPropertyPendingPlaybackRequest,
+ player->GetPendingPlayRequestAndReset());
+ }
+
+ result_.reset(result);
+ return true;
+}
+
+bool SetPlaybackErrorMediaplayerFunction::RunImpl() {
+ std::string url;
+ // Get path string.
+ if (args_->GetString(0, &url))
+ MediaPlayer::GetInstance()->SetPlaybackError(GURL(url));
+ return true;
+}
+
+bool TogglePlaylistPanelMediaplayerFunction::RunImpl() {
+ MediaPlayer::GetInstance()->TogglePlaylistWindowVisible();
+ return true;
+}
+
+bool ToggleFullscreenMediaplayerFunction::RunImpl() {
+ MediaPlayer::GetInstance()->ToggleFullscreen();
+ return true;
+}
diff --git a/chrome/browser/extensions/extension_mediaplayer_private_api.h b/chrome/browser/extensions/extension_mediaplayer_private_api.h
new file mode 100644
index 0000000..42665ea
--- /dev/null
+++ b/chrome/browser/extensions/extension_mediaplayer_private_api.h
@@ -0,0 +1,57 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_MEDIAPLAYER_PRIVATE_API_H_
+#define CHROME_BROWSER_EXTENSIONS_EXTENSION_MEDIAPLAYER_PRIVATE_API_H_
+#pragma once
+
+#include <map>
+#include <string>
+#include <vector>
+
+#include "chrome/browser/extensions/extension_function.h"
+
+// Implements the chrome.mediaplayerPrivate.playAt method.
+class PlayAtMediaplayerFunction
+ : public SyncExtensionFunction {
+ protected:
+ // AsyncExtensionFunction overrides.
+ virtual bool RunImpl() OVERRIDE;
+ DECLARE_EXTENSION_FUNCTION_NAME(
+ "mediaPlayerPrivate.playAt");
+};
+
+// Implements the chrome.mediaPlayerPrivate.getCurrentPlaylist method.
+class GetPlaylistMediaplayerFunction : public SyncExtensionFunction {
+ protected:
+ // AsyncExtensionFunction overrides.
+ virtual bool RunImpl() OVERRIDE;
+ DECLARE_EXTENSION_FUNCTION_NAME("mediaPlayerPrivate.getPlaylist");
+};
+
+// Implements the chrome.mediaPlayerPrivate.setPlaybackError method.
+class SetPlaybackErrorMediaplayerFunction : public SyncExtensionFunction {
+ protected:
+ // AsyncExtensionFunction overrides.
+ virtual bool RunImpl() OVERRIDE;
+ DECLARE_EXTENSION_FUNCTION_NAME("mediaPlayerPrivate.setPlaybackError");
+};
+
+// Implements the chrome.mediaPlayerPrivate.togglePlaylist method.
+class TogglePlaylistPanelMediaplayerFunction : public SyncExtensionFunction {
+ protected:
+ // AsyncExtensionFunction overrides.
+ virtual bool RunImpl() OVERRIDE;
+ DECLARE_EXTENSION_FUNCTION_NAME("mediaPlayerPrivate.togglePlaylistPanel");
+};
+
+// Implements the chrome.mediaPlayerPrivate.toggleFullscreen method.
+class ToggleFullscreenMediaplayerFunction : public SyncExtensionFunction {
+ protected:
+ // AsyncExtensionFunction overrides.
+ virtual bool RunImpl() OVERRIDE;
+ DECLARE_EXTENSION_FUNCTION_NAME("mediaPlayerPrivate.toggleFullscreen");
+};
+
+#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_MEDIAPLAYER_PRIVATE_API_H_
diff --git a/chrome/browser/extensions/extension_service.cc b/chrome/browser/extensions/extension_service.cc
index 65bd8a5..0988692 100644
--- a/chrome/browser/extensions/extension_service.cc
+++ b/chrome/browser/extensions/extension_service.cc
@@ -84,6 +84,7 @@
#if defined(OS_CHROMEOS)
#include "chrome/browser/chromeos/extensions/file_browser_event_router.h"
+#include "chrome/browser/chromeos/extensions/media_player_event_router.h"
#include "webkit/fileapi/file_system_context.h"
#include "webkit/fileapi/file_system_mount_point_provider.h"
#include "webkit/fileapi/file_system_path_manager.h"
@@ -565,6 +566,7 @@ void ExtensionService::InitEventRouters() {
file_browser_event_router_.reset(
new ExtensionFileBrowserEventRouter(profile_));
file_browser_event_router_->ObserveFileSystemEvents();
+ ExtensionMediaPlayerEventRouter::GetInstance()->Init(profile_);
#endif
#if defined(OS_CHROMEOS) && defined(TOUCH_UI)
diff --git a/chrome/browser/extensions/file_manager_util.cc b/chrome/browser/extensions/file_manager_util.cc
index 25253ce..833e817 100644
--- a/chrome/browser/extensions/file_manager_util.cc
+++ b/chrome/browser/extensions/file_manager_util.cc
@@ -8,11 +8,11 @@
#include "base/string_util.h"
#include "base/utf_string_conversions.h"
#include "base/values.h"
+#include "chrome/browser/chromeos/media/media_player.h"
#include "chrome/browser/platform_util.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_list.h"
-#include "chrome/browser/ui/webui/mediaplayer_ui.h"
#include "content/browser/browser_thread.h"
#include "content/browser/user_metrics.h"
#include "grit/generated_resources.h"
@@ -22,11 +22,16 @@
#include "webkit/fileapi/file_system_mount_point_provider.h"
#include "webkit/fileapi/file_system_util.h"
+#define FILEBROWSER_URL(PATH) \
+ ("chrome-extension://hhaomjibdihmijegdhdafkllkbggdgoj/" PATH)
// This is the "well known" url for the file manager extension from
// browser/resources/file_manager. In the future we may provide a way to swap
// out this file manager for an aftermarket part, but not yet.
-const char kBaseFileBrowserUrl[] =
- "chrome-extension://hhaomjibdihmijegdhdafkllkbggdgoj/main.html";
+const char kBaseFileBrowserUrl[] = FILEBROWSER_URL("main.html");
+const char kMediaPlayerUrl[] = FILEBROWSER_URL("mediaplayer.html");
+const char kMediaPlayerPlaylistUrl[] = FILEBROWSER_URL("playlist.html");
+#undef FILEBROWSER_URL
+
// List of file extension we can open in tab.
const char* kBrowserSupportedExtensions[] = {
".jpg", ".jpeg", ".png", ".webp", ".gif", ".pdf", ".txt", ".html", ".htm"
@@ -65,6 +70,16 @@ GURL FileManagerUtil::GetFileBrowserUrl() {
}
// static
+GURL FileManagerUtil::GetMediaPlayerUrl() {
+ return GURL(kMediaPlayerUrl);
+}
+
+// static
+GURL FileManagerUtil::GetMediaPlayerPlaylistUrl() {
+ return GURL(kMediaPlayerPlaylistUrl);
+}
+
+// static
bool FileManagerUtil::ConvertFileToFileSystemUrl(
Profile* profile, const FilePath& full_file_path, const GURL& origin_url,
GURL* url) {
@@ -76,28 +91,14 @@ bool FileManagerUtil::ConvertFileToFileSystemUrl(
return false;
// Find if this file path is managed by the external provider.
- std::vector<FilePath> root_dirs = provider->GetRootDirectories();
- for (std::vector<FilePath>::iterator iter = root_dirs.begin();
- iter != root_dirs.end();
- ++iter) {
- FilePath path;
- std::vector<FilePath::StringType> components;
- const FilePath& root_path = *iter;
- root_path.GetComponents(&components);
- if (!components.size()) {
- NOTREACHED();
- continue;
- }
- if (root_path.AppendRelativePath(full_file_path, &path)) {
- GURL base_url = fileapi::GetFileSystemRootURI(origin_url,
- fileapi::kFileSystemTypeExternal);
- std::string final_url = base_url.spec();
- FilePath relative_path(components[components.size() - 1]);
- *url = GURL(base_url.spec() + relative_path.Append(path).value());
- return true;
- }
- }
- return false;
+ FilePath virtual_path;
+ if (!provider->GetVirtualPath(full_file_path, &virtual_path))
+ return false;
+
+ GURL base_url = fileapi::GetFileSystemRootURI(origin_url,
+ fileapi::kFileSystemTypeExternal);
+ *url = GURL(base_url.spec() + virtual_path.value());
+ return true;
}
// static
diff --git a/chrome/browser/extensions/file_manager_util.h b/chrome/browser/extensions/file_manager_util.h
index 7008874..205b893 100644
--- a/chrome/browser/extensions/file_manager_util.h
+++ b/chrome/browser/extensions/file_manager_util.h
@@ -17,6 +17,9 @@ class FileManagerUtil {
public:
// Gets base file browser url.
static GURL GetFileBrowserUrl();
+ static GURL GetMediaPlayerUrl();
+ static GURL GetMediaPlayerPlaylistUrl();
+
// Converts |full_file_path| into external filesystem: url. Returns false
// if |full_file_path| is not managed by the external filesystem provider.
static bool ConvertFileToFileSystemUrl(Profile* profile,
diff --git a/chrome/browser/resources/component_extension_resources.grd b/chrome/browser/resources/component_extension_resources.grd
index 462a455..c5701bc 100644
--- a/chrome/browser/resources/component_extension_resources.grd
+++ b/chrome/browser/resources/component_extension_resources.grd
@@ -24,6 +24,8 @@
<if expr="pp_ifdef('file_manager_extension')">
<include name="IDR_FILE_MANAGER_MAIN" file="file_manager/main.html" flattenhtml="true" type="BINDATA" />
<include name="IDR_FILE_MANAGER_SLIDESHOW" file="file_manager/slideshow.html" flattenhtml="true" type="BINDATA" />
+ <include name="IDR_FILE_MANAGER_MEDIAPLAYER" file="file_manager/mediaplayer.html" flattenhtml="true" type="BINDATA" />
+ <include name="IDR_FILE_MANAGER_PLAYLIST" file="file_manager/playlist.html" flattenhtml="true" type="BINDATA" />
<include name="IDR_FILE_MANAGER_EXIF_READER" file="file_manager/js/exif_reader.js" type="BINDATA" />
<include name="IDR_FILE_MANAGER_PREVIEW_ICON" file="file_manager/images/icon_preview_16x16.png" type="BINDATA" />
<include name="IDR_FILE_MANAGER_MEDIA_PLAY_ICON" file="file_manager/images/icon_play_16x16.png" type="BINDATA" />
diff --git a/chrome/browser/resources/file_manager/js/file_manager.js b/chrome/browser/resources/file_manager/js/file_manager.js
index 0f83227..4ecc60e 100644
--- a/chrome/browser/resources/file_manager/js/file_manager.js
+++ b/chrome/browser/resources/file_manager/js/file_manager.js
@@ -1622,8 +1622,11 @@ FileManager.prototype = {
return;
}
- var i = this.currentList_.selectionModel.leadIndex;
- var entry = this.dataModel_.item(i);
+ var entry = this.selection.leadEntry;
+ if (!entry) {
+ console.log('Invalid selection');
+ return;
+ }
if (entry.isDirectory)
return this.changeDirectory(entry.fullPath);
diff --git a/chrome/browser/resources/file_manager/manifest.json b/chrome/browser/resources/file_manager/manifest.json
index c6b0871..b6ee025 100644
--- a/chrome/browser/resources/file_manager/manifest.json
+++ b/chrome/browser/resources/file_manager/manifest.json
@@ -11,6 +11,7 @@
"permissions": [
"fileBrowserHandler",
"fileBrowserPrivate",
+ "mediaPlayerPrivate",
"unlimitedStorage",
"chrome://extension-icon/",
"chrome://resources/"
diff --git a/chrome/browser/resources/mediaplayer.html b/chrome/browser/resources/file_manager/mediaplayer.html
index 4b84c0f..9afd746 100644
--- a/chrome/browser/resources/mediaplayer.html
+++ b/chrome/browser/resources/file_manager/mediaplayer.html
@@ -121,11 +121,11 @@ body {
}
.soundiconhigh {
- /* background: TODO(serya): Restore mediaplayer_vol_high.png after moving mediaplayer to extension. */
+ background: url('images/mediaplayer_vol_high.png');
}
.soundiconmuted {
- /* background: TODO(serya): Restore mediaplayer_vol_mute.png after moving mediaplayer to extension. */
+ background: url('images/mediaplayer_vol_mute.png');
}
.soundiconhigh,
@@ -154,13 +154,13 @@ body {
}
.fullscreenicon {
- /* background: TODO(serya): Restore mediaplayer_full_screen.png after moving mediaplayer to extension. */
+ background: url('images/mediaplayer_full_screen.png');
background-repeat: no-repeat;
background-position: 6px 8px;
}
.fullscreenexiticon {
- /* background: TODO(serya): Restore mediaplayer_full_screen_exit.png after moving mediaplayer to extension. */
+ background: url('images/mediaplayer_full_screen_exit.png');
background-repeat: no-repeat;
background-position: 6px 8px;
}
@@ -183,7 +183,7 @@ body {
}
.playicon {
- /* background: TODO(serya): Restore mediaplayer_play.png after moving mediaplayer to extension. */
+ background: url('images/mediaplayer_play.png');
background-repeat: no-repeat;
background-position: 9px 8px;
}
@@ -197,7 +197,7 @@ body {
}
.pauseicon {
- /* background: Restore mediaplayer_pause.png after moving mediaplayer to extension. */
+ background: url('images/mediaplayer_pause.png');
background-repeat: no-repeat;
background-position: 9px 8px;
}
@@ -210,7 +210,7 @@ body {
}
.previcon {
- /* background: TODO(serya): Restore mediaplayer_prev.png after moving mediaplayer to extension. */
+ background: url('images/mediaplayer_prev.png');
background-repeat: no-repeat;
background-position: 6px 8px;
}
@@ -250,7 +250,7 @@ body {
}
.nexticon {
- /* background: TODO(serya): Restore mediaplayer_next.png after moving mediaplayer to extension. */
+ background: url('images/mediaplayer_next.png');
background-repeat: no-repeat;
background-position: 6px 8px;
}
@@ -264,7 +264,7 @@ body {
}
.playlisticon {
- /* background: TODO(serya): Restore mediaplayer_playlist.png after moving mediaplayer to extension. */
+ background: url('images/mediaplayer_playlist.png');
background-repeat: no-repeat;
background-position: 6px 8px;
}
@@ -287,8 +287,8 @@ body {
}
</style>
-<script src="shared/js/local_strings.js"></script>
-<script src="shared/js/media_common.js"></script>
+<script src="chrome://resources/js/local_strings.js"></script>
+<script src="chrome://resources/js/media_common.js"></script>
<script>
function $(o) {
@@ -310,6 +310,14 @@ var fullScreen = false;
* Window onload handler, sets up the page.
*/
function load() {
+ chrome.fileBrowserPrivate.getStrings(function(strings) {
+ localStrings = new LocalStrings(strings);
+
+ init();
+ });
+}
+
+function init() {
document.body.addEventListener('dragover', function(e) {
if (e.preventDefault) e.preventDefault();
});
@@ -318,8 +326,11 @@ function load() {
});
document.body.addEventListener('keydown', onkeydown);
- localStrings = new LocalStrings();
- chrome.send('getCurrentPlaylist', []);
+ chrome.mediaPlayerPrivate.getPlaylist(true, getPlaylistCallback);
+
+ chrome.mediaPlayerPrivate.onPlaylistChanged.addListener(function() {
+ chrome.mediaPlayerPrivate.getPlaylist(true, getPlaylistCallback);
+ });
}
function onMediaProgress() {
@@ -349,12 +360,11 @@ function onLoadedProgress(e) {
function onMediaError(e) {
console.log('Got new error');
console.log(e);
- chrome.send('playbackError', ['Error playing back',
- currentPlaylist[currentItem].path]);
+ chrome.mediaPlayerPrivate.setPlaybackError(currentPlaylist[currentItem].path);
if (currentPlaylist.length == 1) {
- $('error').textContent = localStrings.getString('errorstring');
+ $('error').textContent = localStrings.getString('PLAYBACK_ERROR');
} else {
- chrome.send("showPlaylist", []);
+ chrome.mediaPlayerPrivate.togglePlaylistPanel();
}
onMediaComplete();
}
@@ -380,8 +390,7 @@ function onMediaComplete() {
mediaElement.removeEventListener("play", onMediaPlay, true);
mediaElement.removeEventListener("pause", onMediaPause, true);
mediaElement.onerror = undefined;
- chrome.send('currentOffsetChanged', ['' + currentItem]);
- playMediaFile(currentPlaylist[currentItem].path);
+ chrome.mediaPlayerPrivate.playAt(currentItem);
}
function onMediaPlay() {
@@ -441,7 +450,7 @@ function prevButtonClick() {
currentItem = -1;
return;
}
- chrome.send('currentOffsetChanged', ['' + currentItem]);
+ chrome.mediaPlayerPrivate.playAt(currentItem);
playMediaFile(currentPlaylist[currentItem].path);
}
@@ -451,7 +460,7 @@ function nextButtonClick() {
currentItem = -1;
return;
}
- chrome.send('currentOffsetChanged', ['' + currentItem]);
+ chrome.mediaPlayerPrivate.playAt(currentItem);
playMediaFile(currentPlaylist[currentItem].path);
}
@@ -776,7 +785,7 @@ function toggleFullscreen() {
fullscreenicon.classList.remove('fullscreenexiticon');
fullscreenicon.classList.add('fullscreenicon');
}
- chrome.send('toggleFullscreen', ['']);
+ chrome.mediaPlayerPrivate.toggleFullscreen();
}
function onMetadataAvail() {
@@ -825,52 +834,21 @@ function stopAllPlayback() {
}
}
-function playlistChanged(info, playlist) {
- if (info.force) {
- currentPlaylist = playlist;
- stopAllPlayback();
- if (playlist.length >= 1) {
- if (info.currentOffset) {
- currentItem = info.currentOffset;
- } else {
- currentItem = 0;
- }
- var item = playlist[currentItem];
- chrome.send('currentOffsetChanged', ['' + currentItem]);
- playMediaFile(item.path);
- }
- } else {
- var media = getMediaElement();
- currentPlaylist = playlist;
- // Only need to handle the case where we are not playing
- // since if it is currently playing, it will just move
- // to the next file when the current is complete.
- if (media == null) {
- for (var x = 0; x < playlist.length; x++) {
- if (playlist[x].path == info.path) {
- // found the newly added item.
- currentItem = x;
- chrome.send('currentOffsetChanged', ['' + currentItem]);
- playMediaFile(playlist[x].path);
- return;
- }
- }
- if (playlist.length > 0) {
- currentItem = 0;
- chrome.send('currentOffsetChanged', ['' + currentItem]);
- playMediaFile(playlist[0].path);
- }
- }
+function getPlaylistCallback(playlist) {
+ currentPlaylist = playlist.items;
+ currentItem = playlist.position;
+
+ if (playlist.pendingPlaybackRequest) {
+ playMediaFile(currentPlaylist[currentItem].path);
}
}
function togglePlaylist() {
- chrome.send("togglePlaylist", []);
+ chrome.mediaPlayerPrivate.togglePlaylistPanel();
}
function playMediaFile(url) {
$('error').textContent = '';
- console.log('playfile '+url);
$('title').textContent = '';
if (pathIsVideoFile(url) ) {
playVideoFile(url);
diff --git a/chrome/browser/resources/playlist.html b/chrome/browser/resources/file_manager/playlist.html
index 598844c..5c7ff31 100644
--- a/chrome/browser/resources/playlist.html
+++ b/chrome/browser/resources/file_manager/playlist.html
@@ -52,7 +52,7 @@ body {
}
</style>
-<script src="shared/js/local_strings.js"></script>
+<script src="chrome://resources/js/local_strings.js"></script>
<script>
function $(o) {
@@ -82,7 +82,10 @@ function load() {
document.body.addEventListener('drop', function(e) {
if (e.preventDefault) e.preventDefault();
});
- chrome.send("getCurrentPlaylist", []);
+ chrome.mediaPlayerPrivate.getPlaylist(false, getPlaylistCallback);
+ chrome.mediaPlayerPrivate.onPlaylistChanged.addListener(function() {
+ chrome.mediaPlayerPrivate.getPlaylist(false, getPlaylistCallback);
+ });
};
function getDisplayNameFromPath(path) {
@@ -96,7 +99,7 @@ function getDisplayNameFromPath(path) {
};
function setPlaylistOffset(offset) {
- chrome.send("setCurrentPlaylistOffset", ['' + offset]);
+ chrome.mediaPlayerPrivate.playAt(offset);
};
function updateUI() {
@@ -139,9 +142,9 @@ function updateUI() {
}
};
-function playlistChanged(info, playlist) {
- currentPlaylist = playlist;
- currentOffset = info.currentOffset;
+function getPlaylistCallback(playlist) {
+ currentPlaylist = playlist.items;
+ currentOffset = playlist.position;
updateUI();
};
</script>
diff --git a/chrome/browser/ui/browser_init.cc b/chrome/browser/ui/browser_init.cc
index d85113a..67180645f 100644
--- a/chrome/browser/ui/browser_init.cc
+++ b/chrome/browser/ui/browser_init.cc
@@ -95,7 +95,6 @@
#include "chrome/browser/chromeos/sms_observer.h"
#include "chrome/browser/chromeos/update_observer.h"
#include "chrome/browser/chromeos/wm_message_listener.h"
-#include "chrome/browser/ui/webui/mediaplayer_ui.h"
#endif
#if defined(HAVE_XINPUT2)
diff --git a/chrome/browser/ui/webui/active_downloads_ui.cc b/chrome/browser/ui/webui/active_downloads_ui.cc
index baeb1f2..ab53a62 100644
--- a/chrome/browser/ui/webui/active_downloads_ui.cc
+++ b/chrome/browser/ui/webui/active_downloads_ui.cc
@@ -23,6 +23,7 @@
#include "base/values.h"
#include "chrome/browser/chromeos/cros/cros_library.h"
#include "chrome/browser/chromeos/login/user_manager.h"
+#include "chrome/browser/chromeos/media/media_player.h"
#include "chrome/browser/download/download_item.h"
#include "chrome/browser/download/download_manager.h"
#include "chrome/browser/download/download_util.h"
@@ -33,7 +34,6 @@
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
#include "chrome/browser/ui/webui/favicon_source.h"
-#include "chrome/browser/ui/webui/mediaplayer_ui.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/jstemplate_builder.h"
diff --git a/chrome/browser/ui/webui/chrome_web_ui_factory.cc b/chrome/browser/ui/webui/chrome_web_ui_factory.cc
index 208e265..9936604 100644
--- a/chrome/browser/ui/webui/chrome_web_ui_factory.cc
+++ b/chrome/browser/ui/webui/chrome_web_ui_factory.cc
@@ -47,7 +47,6 @@
#include "chrome/browser/ui/webui/chromeos/sim_unlock_ui.h"
#include "chrome/browser/ui/webui/chromeos/system_info_ui.h"
#include "chrome/browser/ui/webui/active_downloads_ui.h"
-#include "chrome/browser/ui/webui/mediaplayer_ui.h"
#endif
#if defined(TOUCH_UI)
@@ -182,8 +181,6 @@ static WebUIFactoryFunction GetWebUIFactoryFunction(Profile* profile,
return &NewWebUI<ImageBurnUI>;
if (url.host() == chrome::kChromeUIKeyboardOverlayHost)
return &NewWebUI<KeyboardOverlayUI>;
- if (url.host() == chrome::kChromeUIMediaplayerHost)
- return &NewWebUI<MediaplayerUI>;
if (url.host() == chrome::kChromeUIMobileSetupHost)
return &NewWebUI<MobileSetupUI>;
if (url.host() == chrome::kChromeUIProxySettingsHost)
diff --git a/chrome/browser/ui/webui/mediaplayer_ui.cc b/chrome/browser/ui/webui/mediaplayer_ui.cc
deleted file mode 100644
index cb900b0..0000000
--- a/chrome/browser/ui/webui/mediaplayer_ui.cc
+++ /dev/null
@@ -1,624 +0,0 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/ui/webui/mediaplayer_ui.h"
-
-#include "base/command_line.h"
-#include "base/logging.h"
-#include "base/memory/singleton.h"
-#include "base/memory/weak_ptr.h"
-#include "base/message_loop.h"
-#include "base/path_service.h"
-#include "base/string_piece.h"
-#include "base/string_util.h"
-#include "base/threading/thread.h"
-#include "base/time.h"
-#include "base/values.h"
-#include "chrome/browser/bookmarks/bookmark_model.h"
-#include "chrome/browser/download/download_manager.h"
-#include "chrome/browser/download/download_util.h"
-#include "chrome/browser/extensions/file_manager_util.h"
-#include "chrome/browser/history/history_types.h"
-#include "chrome/browser/profiles/profile.h"
-#include "chrome/browser/tabs/tab_strip_model.h"
-#include "chrome/browser/ui/browser.h"
-#include "chrome/browser/ui/browser_list.h"
-#include "chrome/browser/ui/browser_window.h"
-#include "chrome/browser/ui/webui/favicon_source.h"
-#include "chrome/common/chrome_paths.h"
-#include "chrome/common/chrome_switches.h"
-#include "chrome/common/jstemplate_builder.h"
-#include "chrome/common/net/url_fetcher.h"
-#include "chrome/common/time_format.h"
-#include "chrome/common/url_constants.h"
-#include "content/browser/browser_thread.h"
-#include "content/browser/tab_contents/tab_contents.h"
-#include "content/browser/user_metrics.h"
-#include "grit/browser_resources.h"
-#include "grit/chromium_strings.h"
-#include "grit/generated_resources.h"
-#include "grit/locale_settings.h"
-#include "net/base/escape.h"
-#include "net/base/load_flags.h"
-#include "net/url_request/url_request_job.h"
-#include "ui/base/resource/resource_bundle.h"
-
-#if defined(OS_CHROMEOS)
-#include "chrome/browser/chromeos/frame/panel_browser_view.h"
-#endif
-
-static const char kPropertyPath[] = "path";
-static const char kPropertyForce[] = "force";
-static const char kPropertyOffset[] = "currentOffset";
-static const char kPropertyError[] = "error";
-
-static const char* kMediaplayerURL = "chrome://mediaplayer";
-static const char* kMediaplayerPlaylistURL = "chrome://mediaplayer#playlist";
-static const char* kMediaPlayerAppName = "mediaplayer";
-static const int kPopupLeft = 0;
-static const int kPopupTop = 0;
-static const int kPopupWidth = 350;
-static const int kPopupHeight = 300;
-
-class MediaplayerUIHTMLSource : public ChromeURLDataManager::DataSource {
- public:
- explicit MediaplayerUIHTMLSource(bool is_playlist);
-
- // Called when the network layer has requested a resource underneath
- // the path we registered.
- virtual void StartDataRequest(const std::string& path,
- bool is_incognito,
- int request_id);
- virtual std::string GetMimeType(const std::string&) const {
- return "text/html";
- }
-
- private:
- ~MediaplayerUIHTMLSource() {}
- bool is_playlist_;
-
- DISALLOW_COPY_AND_ASSIGN(MediaplayerUIHTMLSource);
-};
-
-// The handler for Javascript messages related to the "mediaplayer" view.
-class MediaplayerHandler : public WebUIMessageHandler,
- public base::SupportsWeakPtr<MediaplayerHandler> {
- public:
-
- struct MediaUrl {
- MediaUrl() {}
- explicit MediaUrl(const GURL& newurl)
- : url(newurl),
- haderror(false) {}
- GURL url;
- bool haderror;
- };
- typedef std::vector<MediaUrl> UrlVector;
-
- explicit MediaplayerHandler(bool is_playlist);
-
- virtual ~MediaplayerHandler();
-
- // Init work after Attach.
- void Init(bool is_playlist, TabContents* contents);
-
- // WebUIMessageHandler implementation.
- virtual WebUIMessageHandler* Attach(WebUI* web_ui);
- virtual void RegisterMessages();
-
- // Callback for the "currentOffsetChanged" message.
- void HandleCurrentOffsetChanged(const ListValue* args);
-
- void FirePlaylistChanged(const std::string& path,
- bool force,
- int offset);
-
- void PlaybackMediaFile(const GURL& url);
-
- void EnqueueMediaFileUrl(const GURL& url);
-
- void GetPlaylistValue(ListValue& args);
-
- // Callback for the "playbackError" message.
- void HandlePlaybackError(const ListValue* args);
-
- // Callback for the "getCurrentPlaylist" message.
- void HandleGetCurrentPlaylist(const ListValue* args);
-
- void HandleTogglePlaylist(const ListValue* args);
- void HandleShowPlaylist(const ListValue* args);
- void HandleSetCurrentPlaylistOffset(const ListValue* args);
- void HandleToggleFullscreen(const ListValue* args);
-
- const UrlVector& GetCurrentPlaylist();
-
- int GetCurrentPlaylistOffset();
- void SetCurrentPlaylistOffset(int offset);
- // Sets the playlist for playlist views, since the playlist is
- // maintained by the mediaplayer itself. Offset is the item in the
- // playlist which is either now playing, or should be played.
- void SetCurrentPlaylist(const UrlVector& playlist, int offset);
-
- private:
- // The current playlist of urls.
- UrlVector current_playlist_;
- // The offset into the current_playlist_ of the currently playing item.
- int current_offset_;
- // Indicator of if this handler is a playlist or a mediaplayer.
- bool is_playlist_;
- DISALLOW_COPY_AND_ASSIGN(MediaplayerHandler);
-};
-
-////////////////////////////////////////////////////////////////////////////////
-//
-// MediaplayerHTMLSource
-//
-////////////////////////////////////////////////////////////////////////////////
-
-MediaplayerUIHTMLSource::MediaplayerUIHTMLSource(bool is_playlist)
- : DataSource(chrome::kChromeUIMediaplayerHost, MessageLoop::current()) {
- is_playlist_ = is_playlist;
-}
-
-void MediaplayerUIHTMLSource::StartDataRequest(const std::string& path,
- bool is_incognito,
- int request_id) {
- DictionaryValue localized_strings;
- // TODO(dhg): Fix the strings that are currently hardcoded so they
- // use the localized versions.
- localized_strings.SetString("errorstring", "Error Playing Back");
-
- SetFontAndTextDirection(&localized_strings);
-
- std::string full_html;
-
- static const base::StringPiece mediaplayer_html(
- ResourceBundle::GetSharedInstance().GetRawDataResource(
- IDR_MEDIAPLAYER_HTML));
-
- static const base::StringPiece playlist_html(
- ResourceBundle::GetSharedInstance().GetRawDataResource(
- IDR_MEDIAPLAYERPLAYLIST_HTML));
-
- if (is_playlist_) {
- full_html = jstemplate_builder::GetI18nTemplateHtml(
- playlist_html, &localized_strings);
- } else {
- full_html = jstemplate_builder::GetI18nTemplateHtml(
- mediaplayer_html, &localized_strings);
- }
-
- scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes);
- html_bytes->data.resize(full_html.size());
- std::copy(full_html.begin(), full_html.end(), html_bytes->data.begin());
-
- SendResponse(request_id, html_bytes);
-}
-
-////////////////////////////////////////////////////////////////////////////////
-//
-// MediaplayerHandler
-//
-////////////////////////////////////////////////////////////////////////////////
-MediaplayerHandler::MediaplayerHandler(bool is_playlist)
- : current_offset_(0),
- is_playlist_(is_playlist) {
-}
-
-MediaplayerHandler::~MediaplayerHandler() {
-}
-
-WebUIMessageHandler* MediaplayerHandler::Attach(WebUI* web_ui) {
- // Create our favicon data source.
- Profile* profile = web_ui->GetProfile();
- profile->GetChromeURLDataManager()->AddDataSource(
- new FaviconSource(profile, FaviconSource::FAVICON));
-
- return WebUIMessageHandler::Attach(web_ui);
-}
-
-void MediaplayerHandler::Init(bool is_playlist, TabContents* contents) {
- MediaPlayer* player = MediaPlayer::GetInstance();
- if (!is_playlist) {
- player->SetNewHandler(this, contents);
- } else {
- player->RegisterNewPlaylistHandler(this, contents);
- }
-}
-
-void MediaplayerHandler::RegisterMessages() {
- web_ui_->RegisterMessageCallback("currentOffsetChanged",
- NewCallback(this, &MediaplayerHandler::HandleCurrentOffsetChanged));
- web_ui_->RegisterMessageCallback("playbackError",
- NewCallback(this, &MediaplayerHandler::HandlePlaybackError));
- web_ui_->RegisterMessageCallback("getCurrentPlaylist",
- NewCallback(this, &MediaplayerHandler::HandleGetCurrentPlaylist));
- web_ui_->RegisterMessageCallback("togglePlaylist",
- NewCallback(this, &MediaplayerHandler::HandleTogglePlaylist));
- web_ui_->RegisterMessageCallback("setCurrentPlaylistOffset",
- NewCallback(this, &MediaplayerHandler::HandleSetCurrentPlaylistOffset));
- web_ui_->RegisterMessageCallback("toggleFullscreen",
- NewCallback(this, &MediaplayerHandler::HandleToggleFullscreen));
- web_ui_->RegisterMessageCallback("showPlaylist",
- NewCallback(this, &MediaplayerHandler::HandleShowPlaylist));
-}
-
-void MediaplayerHandler::GetPlaylistValue(ListValue& urls) {
- for (size_t x = 0; x < current_playlist_.size(); x++) {
- DictionaryValue* url_value = new DictionaryValue();
- url_value->SetString(kPropertyPath, current_playlist_[x].url.spec());
- url_value->SetBoolean(kPropertyError, current_playlist_[x].haderror);
- urls.Append(url_value);
- }
-}
-
-void MediaplayerHandler::PlaybackMediaFile(const GURL& url) {
- current_playlist_.push_back(MediaplayerHandler::MediaUrl(url));
- FirePlaylistChanged(url.spec(), true, current_playlist_.size() - 1);
- MediaPlayer::GetInstance()->NotifyPlaylistChanged();
-}
-
-const MediaplayerHandler::UrlVector& MediaplayerHandler::GetCurrentPlaylist() {
- return current_playlist_;
-}
-
-int MediaplayerHandler::GetCurrentPlaylistOffset() {
- return current_offset_;
-}
-
-void MediaplayerHandler::HandleToggleFullscreen(const ListValue* args) {
- MediaPlayer::GetInstance()->ToggleFullscreen();
-}
-
-void MediaplayerHandler::HandleSetCurrentPlaylistOffset(const ListValue* args) {
- int id;
- CHECK(ExtractIntegerValue(args, &id));
- MediaPlayer::GetInstance()->SetPlaylistOffset(id);
-}
-
-void MediaplayerHandler::FirePlaylistChanged(const std::string& path,
- bool force,
- int offset) {
- DictionaryValue info_value;
- ListValue urls;
- GetPlaylistValue(urls);
- info_value.SetString(kPropertyPath, path);
- info_value.SetBoolean(kPropertyForce, force);
- info_value.SetInteger(kPropertyOffset, offset);
- web_ui_->CallJavascriptFunction("playlistChanged", info_value, urls);
-}
-
-void MediaplayerHandler::SetCurrentPlaylistOffset(int offset) {
- current_offset_ = offset;
- FirePlaylistChanged(std::string(), true, current_offset_);
-}
-
-void MediaplayerHandler::SetCurrentPlaylist(
- const MediaplayerHandler::UrlVector& playlist, int offset) {
- current_playlist_ = playlist;
- current_offset_ = offset;
- FirePlaylistChanged(std::string(), false, current_offset_);
-}
-
-void MediaplayerHandler::EnqueueMediaFileUrl(const GURL& url) {
- current_playlist_.push_back(MediaplayerHandler::MediaUrl(url));
- FirePlaylistChanged(url.spec(), false, current_offset_);
- MediaPlayer::GetInstance()->NotifyPlaylistChanged();
-}
-
-void MediaplayerHandler::HandleCurrentOffsetChanged(const ListValue* args) {
- CHECK(ExtractIntegerValue(args, &current_offset_));
- MediaPlayer::GetInstance()->NotifyPlaylistChanged();
-}
-
-void MediaplayerHandler::HandlePlaybackError(const ListValue* args) {
- std::string error;
- std::string url;
- // Get path string.
- if (args->GetString(0, &error))
- LOG(ERROR) << "Playback error" << error;
- if (args->GetString(1, &url)) {
- for (size_t x = 0; x < current_playlist_.size(); x++) {
- if (current_playlist_[x].url == GURL(url)) {
- current_playlist_[x].haderror = true;
- }
- }
- FirePlaylistChanged(std::string(), false, current_offset_);
- }
-}
-
-void MediaplayerHandler::HandleGetCurrentPlaylist(const ListValue* args) {
- FirePlaylistChanged(std::string(), false, current_offset_);
-}
-
-void MediaplayerHandler::HandleTogglePlaylist(const ListValue* args) {
- MediaPlayer::GetInstance()->TogglePlaylistWindowVisible();
-}
-
-void MediaplayerHandler::HandleShowPlaylist(const ListValue* args) {
- MediaPlayer::GetInstance()->ShowPlaylistWindow();
-}
-
-////////////////////////////////////////////////////////////////////////////////
-//
-// Mediaplayer
-//
-////////////////////////////////////////////////////////////////////////////////
-
-// Allows InvokeLater without adding refcounting. This class is a Singleton and
-// won't be deleted until it's last InvokeLater is run.
-DISABLE_RUNNABLE_METHOD_REFCOUNT(MediaPlayer);
-
-MediaPlayer::~MediaPlayer() {
-}
-
-// static
-MediaPlayer* MediaPlayer::GetInstance() {
- return Singleton<MediaPlayer>::get();
-}
-
-void MediaPlayer::EnqueueMediaFile(Profile* profile, const FilePath& file_path,
- Browser* creator) {
- static GURL origin_url(kMediaplayerURL);
- GURL url;
- if (!FileManagerUtil::ConvertFileToFileSystemUrl(profile, file_path,
- origin_url, &url)) {
- }
- EnqueueMediaFileUrl(url, creator);
-}
-
-void MediaPlayer::EnqueueMediaFileUrl(const GURL& url, Browser* creator) {
- if (handler_ == NULL) {
- unhandled_urls_.push_back(url);
- PopupMediaPlayer(creator);
- } else {
- handler_->EnqueueMediaFileUrl(url);
- }
-}
-
-void MediaPlayer::ForcePlayMediaFile(Profile* profile,
- const FilePath& file_path,
- Browser* creator) {
- static GURL origin_url(kMediaplayerURL);
- GURL url;
- if (!FileManagerUtil::ConvertFileToFileSystemUrl(profile, file_path,
- origin_url, &url)) {
- }
- ForcePlayMediaURL(url, creator);
-}
-
-void MediaPlayer::ForcePlayMediaURL(const GURL& url, Browser* creator) {
- if (handler_ == NULL) {
- unhandled_urls_.push_back(url);
- PopupMediaPlayer(creator);
- } else {
- handler_->PlaybackMediaFile(url);
- }
-}
-
-void MediaPlayer::TogglePlaylistWindowVisible() {
- if (playlist_browser_) {
- ClosePlaylistWindow();
- } else {
- ShowPlaylistWindow();
- }
-}
-
-void MediaPlayer::ShowPlaylistWindow() {
- if (playlist_browser_ == NULL) {
- PopupPlaylist(NULL);
- }
-}
-
-void MediaPlayer::ClosePlaylistWindow() {
- if (playlist_browser_ != NULL) {
- playlist_browser_->window()->Close();
- }
-}
-
-void MediaPlayer::SetPlaylistOffset(int offset) {
- if (handler_) {
- handler_->SetCurrentPlaylistOffset(offset);
- }
- if (playlist_) {
- playlist_->SetCurrentPlaylistOffset(offset);
- }
-}
-
-void MediaPlayer::SetNewHandler(MediaplayerHandler* handler,
- TabContents* contents) {
- handler_ = handler;
- mediaplayer_tab_ = contents;
- RegisterListeners();
- for (size_t x = 0; x < unhandled_urls_.size(); x++) {
- handler_->EnqueueMediaFileUrl(unhandled_urls_[x]);
- }
- unhandled_urls_.clear();
-}
-
-void MediaPlayer::RegisterListeners() {
- registrar_.RemoveAll();
- if (playlist_tab_) {
- registrar_.Add(this,
- NotificationType::TAB_CONTENTS_DESTROYED,
- Source<TabContents>(playlist_tab_));
- }
- if (mediaplayer_tab_) {
- registrar_.Add(this,
- NotificationType::TAB_CONTENTS_DESTROYED,
- Source<TabContents>(mediaplayer_tab_));
- }
-};
-
-void MediaPlayer::Observe(NotificationType type,
- const NotificationSource& source,
- const NotificationDetails& details) {
- DCHECK(type == NotificationType::TAB_CONTENTS_DESTROYED);
- if (Source<TabContents>(source).ptr() == mediaplayer_tab_) {
- RemoveHandler(handler_);
- RegisterListeners();
- ClosePlaylistWindow();
- } else if (Source<TabContents>(source).ptr() == playlist_tab_) {
- RemovePlaylistHandler(playlist_);
- RegisterListeners();
- }
-}
-
-void MediaPlayer::RegisterNewPlaylistHandler(MediaplayerHandler* handler,
- TabContents* contents) {
- playlist_ = handler;
- playlist_tab_ = contents;
- RegisterListeners();
- NotifyPlaylistChanged();
-}
-
-void MediaPlayer::RemovePlaylistHandler(MediaplayerHandler* handler) {
- if (handler == playlist_) {
- playlist_ = NULL;
- playlist_browser_ = NULL;
- playlist_tab_ = NULL;
- }
-}
-
-void MediaPlayer::NotifyPlaylistChanged() {
- if (handler_ && playlist_) {
- playlist_->SetCurrentPlaylist(handler_->GetCurrentPlaylist(),
- handler_->GetCurrentPlaylistOffset());
- }
-}
-
-void MediaPlayer::ToggleFullscreen() {
- if (handler_ && mediaplayer_browser_) {
- mediaplayer_browser_->ToggleFullscreenMode();
- }
-}
-
-void MediaPlayer::RemoveHandler(MediaplayerHandler* handler) {
- if (handler == handler_) {
- handler_ = NULL;
- mediaplayer_browser_ = NULL;
- mediaplayer_tab_ = NULL;
- }
-}
-
-void MediaPlayer::PopupPlaylist(Browser* creator) {
- Profile* profile = BrowserList::GetLastActive()->profile();
- playlist_browser_ = Browser::CreateForApp(Browser::TYPE_PANEL,
- kMediaPlayerAppName,
- gfx::Size(),
- profile);
- playlist_browser_->AddSelectedTabWithURL(GURL(kMediaplayerPlaylistURL),
- PageTransition::LINK);
- playlist_browser_->window()->SetBounds(gfx::Rect(kPopupLeft,
- kPopupTop,
- kPopupWidth,
- kPopupHeight));
- playlist_browser_->window()->Show();
-}
-
-void MediaPlayer::PopupMediaPlayer(Browser* creator) {
- if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
- BrowserThread::PostTask(
- BrowserThread::UI, FROM_HERE,
- NewRunnableMethod(this, &MediaPlayer::PopupMediaPlayer,
- static_cast<Browser*>(NULL)));
- return;
- }
- Profile* profile = BrowserList::GetLastActive()->profile();
- mediaplayer_browser_ = Browser::CreateForApp(Browser::TYPE_PANEL,
- kMediaPlayerAppName,
- gfx::Size(),
- profile);
-#if defined(OS_CHROMEOS)
- // Since we are on chromeos, popups should be a PanelBrowserView,
- // so we can just cast it.
- if (creator) {
- chromeos::PanelBrowserView* creatorview =
- static_cast<chromeos::PanelBrowserView*>(creator->window());
- chromeos::PanelBrowserView* view =
- static_cast<chromeos::PanelBrowserView*>(
- mediaplayer_browser_->window());
- view->SetCreatorView(creatorview);
- }
-#endif
- mediaplayer_browser_->AddSelectedTabWithURL(GURL(kMediaplayerURL),
- PageTransition::LINK);
- mediaplayer_browser_->window()->SetBounds(gfx::Rect(kPopupLeft,
- kPopupTop,
- kPopupWidth,
- kPopupHeight));
- mediaplayer_browser_->window()->Show();
-}
-
-net::URLRequestJob* MediaPlayer::MaybeIntercept(net::URLRequest* request) {
- // Don't attempt to intercept here as we want to wait until the mime
- // type is fully determined.
- return NULL;
-}
-
-// This is the list of mime types currently supported by the Google
-// Document Viewer.
-static const char* const supported_mime_type_list[] = {
- "audio/mpeg",
- "video/mp4",
- "audio/mp3"
-};
-
-net::URLRequestJob* MediaPlayer::MaybeInterceptResponse(
- net::URLRequest* request) {
- // Do not intercept this request if it is a download.
- if (request->load_flags() & net::LOAD_IS_DOWNLOAD) {
- return NULL;
- }
-
- std::string mime_type;
- request->GetMimeType(&mime_type);
- // If it is in our list of known URLs, enqueue the url then
- // Cancel the request so the mediaplayer can handle it when
- // it hits it in the playlist.
- if (supported_mime_types_.find(mime_type) != supported_mime_types_.end()) {
- if (request->referrer() != chrome::kChromeUIMediaplayerURL &&
- !request->referrer().empty()) {
- EnqueueMediaFileUrl(request->url(), NULL);
- request->Cancel();
- }
- }
- return NULL;
-}
-
-MediaPlayer::MediaPlayer()
- : handler_(NULL),
- playlist_(NULL),
- playlist_browser_(NULL),
- mediaplayer_browser_(NULL),
- mediaplayer_tab_(NULL),
- playlist_tab_(NULL) {
- for (size_t i = 0; i < arraysize(supported_mime_type_list); ++i) {
- supported_mime_types_.insert(supported_mime_type_list[i]);
- }
-};
-
-////////////////////////////////////////////////////////////////////////////////
-//
-// MediaplayerUIContents
-//
-////////////////////////////////////////////////////////////////////////////////
-
-MediaplayerUI::MediaplayerUI(TabContents* contents) : WebUI(contents) {
- const GURL& url = contents->GetURL();
- bool is_playlist = (url.ref() == "playlist");
- MediaplayerHandler* handler = new MediaplayerHandler(is_playlist);
- AddMessageHandler(handler->Attach(this));
- if (is_playlist) {
- handler->Init(true, contents);
- } else {
- handler->Init(false, contents);
- }
-
- MediaplayerUIHTMLSource* html_source =
- new MediaplayerUIHTMLSource(is_playlist);
-
- // Set up the chrome://mediaplayer/ source.
- contents->profile()->GetChromeURLDataManager()->AddDataSource(html_source);
-}
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index c176df2..e02aa76 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -416,6 +416,8 @@
'browser/chromeos/enterprise_extension_observer.h',
'browser/chromeos/extensions/file_browser_event_router.cc',
'browser/chromeos/extensions/file_browser_event_router.h',
+ 'browser/chromeos/extensions/media_player_event_router.cc',
+ 'browser/chromeos/extensions/media_player_event_router.h',
'browser/chromeos/external_metrics.cc',
'browser/chromeos/external_metrics.h',
'browser/chromeos/external_protocol_dialog.cc',
@@ -619,6 +621,8 @@
'browser/chromeos/login/wizard_screen.h',
'browser/chromeos/low_battery_observer.cc',
'browser/chromeos/low_battery_observer.h',
+ 'browser/chromeos/media/media_player.cc',
+ 'browser/chromeos/media/media_player.h',
'browser/chromeos/metrics_cros_settings_provider.cc',
'browser/chromeos/metrics_cros_settings_provider.h',
'browser/chromeos/name_value_pairs_parser.cc',
@@ -958,6 +962,8 @@
'browser/extensions/extension_management_api.h',
'browser/extensions/extension_menu_manager.cc',
'browser/extensions/extension_menu_manager.h',
+ 'browser/extensions/extension_mediaplayer_private_api.h',
+ 'browser/extensions/extension_mediaplayer_private_api.cc',
'browser/extensions/extension_message_handler.cc',
'browser/extensions/extension_message_handler.h',
'browser/extensions/extension_message_service.cc',
@@ -3341,8 +3347,6 @@
'browser/ui/webui/html_dialog_ui.h',
'browser/ui/webui/keyboard_ui.cc',
'browser/ui/webui/keyboard_ui.h',
- 'browser/ui/webui/mediaplayer_ui.cc',
- 'browser/ui/webui/mediaplayer_ui.h',
'browser/ui/webui/net_internals_ui.cc',
'browser/ui/webui/net_internals_ui.h',
'browser/ui/webui/ntp/app_launcher_handler.cc',
@@ -3552,6 +3556,8 @@
['exclude', '^browser/ui/webui/options/chromeos'],
['exclude', 'browser/extensions/extension_file_browser_private_api.cc'],
['exclude', 'browser/extensions/extension_file_browser_private_api.h'],
+ ['exclude', 'browser/extensions/extension_mediaplayer_private_api.cc'],
+ ['exclude', 'browser/extensions/extension_mediaplayer_private_api.h'],
['exclude', 'browser/extensions/extension_tts_api_chromeos.cc'],
['exclude', 'browser/extensions/file_manager_util.h'],
['exclude', 'browser/extensions/file_manager_util.cc'],
@@ -3575,7 +3581,6 @@
['exclude', 'browser/ui/webui/cookies_tree_model_adapter.h'],
['exclude', 'browser/ui/webui/fileicon_source_cros.cc'],
['exclude', 'browser/ui/webui/fileicon_source_cros.h'],
- ['exclude', 'browser/ui/webui/mediaplayer_ui.cc'],
],
}],
['chromeos==1', {
diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi
index 6dcd2cc..31b7ce7 100644
--- a/chrome/chrome_tests.gypi
+++ b/chrome/chrome_tests.gypi
@@ -2286,6 +2286,7 @@
'browser/chromeos/login/wizard_controller_browsertest.cc',
'browser/chromeos/login/wizard_in_process_browser_test.cc',
'browser/chromeos/login/wizard_in_process_browser_test.h',
+ 'browser/chromeos/media/media_player_browsertest.cc',
'browser/chromeos/network_state_notifier_browsertest.cc',
'browser/chromeos/notifications/notification_browsertest.cc',
'browser/chromeos/panels/panel_browsertest.cc',
@@ -2429,7 +2430,6 @@
'browser/ui/views/dom_view_browsertest.cc',
'browser/ui/views/html_dialog_view_browsertest.cc',
'browser/ui/webui/chrome_url_data_manager_browsertest.cc',
- 'browser/ui/webui/mediaplayer_browsertest.cc',
'browser/ui/webui/ntp/most_visited_browsertest.cc',
'browser/ui/webui/settings_browsertest.cc',
'browser/ui/webui/test_chrome_web_ui_factory_browsertest.cc',
@@ -2485,7 +2485,7 @@
['exclude', '^browser/chromeos'],
],
'sources!': [
- 'browser/ui/webui/mediaplayer_browsertest.cc',
+ 'browser/chromeos/media/media_player_browsertest.cc',
],
}, { #else: OS == "chromeos"
'sources!': [
diff --git a/chrome/common/extensions/api/extension_api.json b/chrome/common/extensions/api/extension_api.json
index 0db97a3..ecff234 100644
--- a/chrome/common/extensions/api/extension_api.json
+++ b/chrome/common/extensions/api/extension_api.json
@@ -5112,6 +5112,110 @@
]
},
{
+ "namespace": "mediaPlayerPrivate",
+ "nodoc": "true",
+ "types": [
+ {
+ "id": "Playlist",
+ "type": "object",
+ "description": "Mediaplayer playlist stored in the browser (it extsts even if the mediaplayer is closed).",
+ "properties": {
+ "items": {
+ "name": "items",
+ "type": "array",
+ "items": {
+ "type": "object",
+ "properties": {
+ "path": { "type": "string", "description": "URL of mediafile (in 'filesystem:' scheme for local files)." },
+ "error": { "type": "boolean", "description": "True if the file has failed to play ('playbackError' with its URL called)." }
+ }
+ }
+ },
+ "position": {
+ "type": "integer",
+ "description": "Index of item in the 'items' array to play next."
+ },
+ "pendingPlaybackRequest": {
+ "type": "boolean",
+ "optional": "true",
+ "description": "Informs that a request to play current item has been received. This flag is reset automatically."
+ }
+ }
+ }
+ ],
+ "functions": [
+ {
+ "name": "playAt",
+ "description": "Sets playlist positions and sets flag of pending play request. Then fires the onPlaylistChanged event.",
+ "parameters": [
+ {
+ "name": "position",
+ "type": "integer",
+ "description": "New position in the playlist."
+ }
+ ]
+ },
+ {
+ "name": "setPlaybackError",
+ "description": "Marks the URL as failed to play one. Mediaplayer will visually marks such an item. Then fires the onPlaylistChanged event.",
+ "parameters": [
+ {
+ "name": "url",
+ "type": "string",
+ "description": "URL failed to play."
+ }
+ ]
+ },
+ {
+ "name": "getPlaylist",
+ "type": "function",
+ "description": "Returns current play list, position and flag of penging play request.",
+ "parameters": [
+ {
+ "name": "resetPendingPlaybackRequest",
+ "type": "boolean",
+ "description": "If true the result will include pending playback request status and this status will be reset."
+ },
+ {
+ "name": "callback",
+ "type": "function",
+ "description": "Callback to retrieve the playlist.",
+ "parameters": [
+ {
+ "name": "playlist",
+ "$ref": "Playlist",
+ "description": "Mediaplayer playlist stored in the browser (it extsts even if the mediaplayer is closed)."
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "name": "togglePlaylistPanel",
+ "description": "Shows or hides the playlist panel.",
+ "parameters": []
+ },
+ {
+ "name": "toggleFullscreen",
+ "description": "Switches fullscreen mode on/off for the mediaplayer.",
+ "parameters": []
+ },
+ {
+ "name": "showPlaylistPanel",
+ "description": "Shows the playlist panel.",
+ "parameters": []
+ }
+ ],
+ "events": [
+ {
+ "name": "onPlaylistChanged",
+ "type": "function",
+ "descrition": "Notifies that playlist content or state has been changed. Data could be retrieved via 'getPlaylist'.",
+ "parameters": []
+ }
+ ]
+ },
+ {
"namespace":"webstorePrivate",
"nodoc": "true",
"functions": [
diff --git a/chrome/common/extensions/extension.cc b/chrome/common/extensions/extension.cc
index bd62b97..00d22a7 100644
--- a/chrome/common/extensions/extension.cc
+++ b/chrome/common/extensions/extension.cc
@@ -280,6 +280,7 @@ const char Extension::kGeolocationPermission[] = "geolocation";
const char Extension::kHistoryPermission[] = "history";
const char Extension::kIdlePermission[] = "idle";
const char Extension::kManagementPermission[] = "management";
+const char Extension::kMediaPlayerPrivatePermission[] = "mediaPlayerPrivate";
const char Extension::kNotificationPermission[] = "notifications";
const char Extension::kProxyPermission[] = "proxy";
const char Extension::kTabPermission[] = "tabs";
@@ -309,6 +310,7 @@ const Extension::Permission Extension::kPermissions[] = {
{ kHistoryPermission, PermissionMessage::ID_BROWSING_HISTORY },
{ kIdlePermission, PermissionMessage::ID_NONE },
{ kManagementPermission, PermissionMessage::ID_MANAGEMENT },
+ { kMediaPlayerPrivatePermission, PermissionMessage::ID_NONE },
{ kNotificationPermission, PermissionMessage::ID_NONE },
{ kProxyPermission, PermissionMessage::ID_NONE },
{ kTabPermission, PermissionMessage::ID_TABS },
@@ -334,6 +336,7 @@ const size_t Extension::kNumHostedAppPermissions =
const char* const Extension::kComponentPrivatePermissionNames[] = {
Extension::kFileBrowserPrivatePermission,
Extension::kWebstorePrivatePermission,
+ Extension::kMediaPlayerPrivatePermission,
Extension::kChromeosInfoPrivatePermission,
};
const size_t Extension::kNumComponentPrivatePermissions =
diff --git a/chrome/common/extensions/extension.h b/chrome/common/extensions/extension.h
index cabba05..58a57d8 100644
--- a/chrome/common/extensions/extension.h
+++ b/chrome/common/extensions/extension.h
@@ -293,6 +293,7 @@ class Extension : public base::RefCountedThreadSafe<Extension> {
static const char kHistoryPermission[];
static const char kIdlePermission[];
static const char kManagementPermission[];
+ static const char kMediaPlayerPrivatePermission[];
static const char kNotificationPermission[];
static const char kProxyPermission[];
static const char kTabPermission[];
diff --git a/chrome/common/extensions/extension_unittest.cc b/chrome/common/extensions/extension_unittest.cc
index 804f92b..a7b3d83 100644
--- a/chrome/common/extensions/extension_unittest.cc
+++ b/chrome/common/extensions/extension_unittest.cc
@@ -1034,6 +1034,7 @@ TEST(ExtensionTest, PermissionMessages) {
// These are private.
skip.insert(Extension::kWebstorePrivatePermission);
skip.insert(Extension::kFileBrowserPrivatePermission);
+ skip.insert(Extension::kMediaPlayerPrivatePermission);
skip.insert(Extension::kChromePrivatePermission);
skip.insert(Extension::kChromeosInfoPrivatePermission);
skip.insert(Extension::kWebSocketProxyPrivatePermission);
diff --git a/chrome/renderer/resources/renderer_extension_bindings.js b/chrome/renderer/resources/renderer_extension_bindings.js
index f773303..aeede6d 100644
--- a/chrome/renderer/resources/renderer_extension_bindings.js
+++ b/chrome/renderer/resources/renderer_extension_bindings.js
@@ -321,6 +321,7 @@ var chrome = chrome || {};
"history",
"idle",
"management",
+ "mediaPlayerPrivate",
"omnibox",
"pageAction",
"pageActions",
diff --git a/webkit/chromeos/fileapi/cros_mount_point_provider.cc b/webkit/chromeos/fileapi/cros_mount_point_provider.cc
index b5d40ae..74df6d8 100644
--- a/webkit/chromeos/fileapi/cros_mount_point_provider.cc
+++ b/webkit/chromeos/fileapi/cros_mount_point_provider.cc
@@ -173,5 +173,19 @@ std::vector<FilePath> CrosMountPointProvider::GetRootDirectories() const {
return root_dirs;
}
+bool CrosMountPointProvider::GetVirtualPath(const FilePath& filesystem_path,
+ FilePath* virtual_path) {
+ for (MountPointMap::const_iterator iter = mount_point_map_.begin();
+ iter != mount_point_map_.end();
+ ++iter) {
+ FilePath mount_prefix = iter->second.Append(iter->first);
+ *virtual_path = FilePath(iter->first);
+ if (mount_prefix.AppendRelativePath(filesystem_path, virtual_path)) {
+ return true;
+ }
+ }
+ return false;
+}
+
} // namespace chromeos
diff --git a/webkit/chromeos/fileapi/cros_mount_point_provider.h b/webkit/chromeos/fileapi/cros_mount_point_provider.h
index 7c48df4..40afae2 100644
--- a/webkit/chromeos/fileapi/cros_mount_point_provider.h
+++ b/webkit/chromeos/fileapi/cros_mount_point_provider.h
@@ -52,6 +52,8 @@ class CrosMountPointProvider
const std::string& extension_id) OVERRIDE;
virtual void AddMountPoint(FilePath mount_point) OVERRIDE;
virtual void RemoveMountPoint(FilePath mount_point) OVERRIDE;
+ virtual bool GetVirtualPath(const FilePath& filesystem_path,
+ FilePath* virtual_path) OVERRIDE;
private:
class GetFileSystemRootPathTask;
diff --git a/webkit/fileapi/file_system_mount_point_provider.h b/webkit/fileapi/file_system_mount_point_provider.h
index 50e0d39..edf158f 100644
--- a/webkit/fileapi/file_system_mount_point_provider.h
+++ b/webkit/fileapi/file_system_mount_point_provider.h
@@ -70,7 +70,11 @@ class ExternalFileSystemMountPointProvider
// Adds a new mount point.
virtual void AddMountPoint(FilePath mount_point) = 0;
// Remove a mount point.
- virtual void RemoveMountPoint(FilePath mount_point) = 0;
+ virtual void RemoveMountPoint(FilePath mount_point) = 0;
+ // Gets virtual path by known filesystem path. Returns false when filesystem
+ // path is not exposed by this provider.
+ virtual bool GetVirtualPath(const FilePath& filesystem_path,
+ FilePath* virtual_path) = 0;
};
} // namespace fileapi