diff options
author | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-11 01:10:45 +0000 |
---|---|---|
committer | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-11 01:10:45 +0000 |
commit | b4037d13ad107e6fc72e1149ed4f760e08aedd9a (patch) | |
tree | 370e5a60e694bab5d7e6dc04010c5c2a966fd6d0 /chrome | |
parent | e896a4d2af4d4c15aeeeb66fb2b18950f777f103 (diff) | |
download | chromium_src-b4037d13ad107e6fc72e1149ed4f760e08aedd9a.zip chromium_src-b4037d13ad107e6fc72e1149ed4f760e08aedd9a.tar.gz chromium_src-b4037d13ad107e6fc72e1149ed4f760e08aedd9a.tar.bz2 |
Lands http://codereview.chromium.org/379007 for Dave:
Fixes leak in BackingStore as shown by valgrind. XFree doesn't free
the data of the image, where as XDestroyImage does.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/391008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@31633 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/app/theme/filebrowse_back.png | bin | 0 -> 482 bytes | |||
-rw-r--r-- | chrome/app/theme/filebrowse_forward.png | bin | 0 -> 465 bytes | |||
-rw-r--r-- | chrome/app/theme/icon_app.png | bin | 0 -> 236 bytes | |||
-rw-r--r-- | chrome/app/theme/icon_file.png | bin | 0 -> 274 bytes | |||
-rw-r--r-- | chrome/app/theme/icon_folder.png | bin | 0 -> 263 bytes | |||
-rw-r--r-- | chrome/app/theme/icon_media.png | bin | 0 -> 301 bytes | |||
-rw-r--r-- | chrome/app/theme/icon_photo.png | bin | 0 -> 335 bytes | |||
-rw-r--r-- | chrome/app/theme/icon_webpage.png | bin | 0 -> 526 bytes | |||
-rw-r--r-- | chrome/app/theme/theme_resources.grd | 10 | ||||
-rw-r--r-- | chrome/browser/browser_init.cc | 10 | ||||
-rw-r--r-- | chrome/browser/chromeos/mount_library.cc | 98 | ||||
-rw-r--r-- | chrome/browser/chromeos/mount_library.h | 91 | ||||
-rw-r--r-- | chrome/browser/chromeos/usb_mount_observer.cc | 91 | ||||
-rw-r--r-- | chrome/browser/chromeos/usb_mount_observer.h | 61 | ||||
-rw-r--r-- | chrome/browser/resources/filebrowse.html | 405 | ||||
-rwxr-xr-x | chrome/chrome.gyp | 4 |
16 files changed, 702 insertions, 68 deletions
diff --git a/chrome/app/theme/filebrowse_back.png b/chrome/app/theme/filebrowse_back.png Binary files differnew file mode 100644 index 0000000..9fd71bd --- /dev/null +++ b/chrome/app/theme/filebrowse_back.png diff --git a/chrome/app/theme/filebrowse_forward.png b/chrome/app/theme/filebrowse_forward.png Binary files differnew file mode 100644 index 0000000..1476ae3 --- /dev/null +++ b/chrome/app/theme/filebrowse_forward.png diff --git a/chrome/app/theme/icon_app.png b/chrome/app/theme/icon_app.png Binary files differnew file mode 100644 index 0000000..e6e395b --- /dev/null +++ b/chrome/app/theme/icon_app.png diff --git a/chrome/app/theme/icon_file.png b/chrome/app/theme/icon_file.png Binary files differnew file mode 100644 index 0000000..440aa4b --- /dev/null +++ b/chrome/app/theme/icon_file.png diff --git a/chrome/app/theme/icon_folder.png b/chrome/app/theme/icon_folder.png Binary files differnew file mode 100644 index 0000000..33a017c --- /dev/null +++ b/chrome/app/theme/icon_folder.png diff --git a/chrome/app/theme/icon_media.png b/chrome/app/theme/icon_media.png Binary files differnew file mode 100644 index 0000000..c489b2e --- /dev/null +++ b/chrome/app/theme/icon_media.png diff --git a/chrome/app/theme/icon_photo.png b/chrome/app/theme/icon_photo.png Binary files differnew file mode 100644 index 0000000..e263c55 --- /dev/null +++ b/chrome/app/theme/icon_photo.png diff --git a/chrome/app/theme/icon_webpage.png b/chrome/app/theme/icon_webpage.png Binary files differnew file mode 100644 index 0000000..90f9fe9 --- /dev/null +++ b/chrome/app/theme/icon_webpage.png diff --git a/chrome/app/theme/theme_resources.grd b/chrome/app/theme/theme_resources.grd index a3ce0e5..f76f977 100644 --- a/chrome/app/theme/theme_resources.grd +++ b/chrome/app/theme/theme_resources.grd @@ -399,7 +399,15 @@ <include name="IDR_STATUSBAR_WIFI_UP3P" file="statusbar_wifi_up3p.png" type="BINDATA" /> <include name="IDR_STATUSBAR_WARNING" file="statusbar_wifi_warning.png" type="BINDATA" /> <include name="IDR_STATUSBAR_WIRED" file="statusbar_wired.png" type="BINDATA" /> - </if> + <include name="IDR_FILEBROWSER_BACK" file="filebrowse_back.png" type="BINDATA" /> + <include name="IDR_FILEBROWSER_FWD" file="filebrowse_forward.png" type="BINDATA" /> + <include name="IDR_ICON_APP" file="icon_app.png" type="BINDATA" /> + <include name="IDR_ICON_FILE" file="icon_file.png" type="BINDATA" /> + <include name="IDR_ICON_FOLDER" file="icon_folder.png" type="BINDATA" /> + <include name="IDR_ICON_MEDIA" file="icon_media.png" type="BINDATA" /> + <include name="IDR_ICON_PHOTO" file="icon_photo.png" type="BINDATA" /> + <include name="IDR_ICON_WEBPAGE" file="icon_webpage.png" type="BINDATA" /> + </if> <if expr="(pp_ifdef('chromeos') or pp_ifdef('toolkit_views')) and pp_ifdef('_google_chrome')"> <include name="IDR_MAIN_MENU_BUTTON" file="google_chrome/button_menu.png" type="BINDATA" /> diff --git a/chrome/browser/browser_init.cc b/chrome/browser/browser_init.cc index 5a08089..bfc3f5e 100644 --- a/chrome/browser/browser_init.cc +++ b/chrome/browser/browser_init.cc @@ -49,6 +49,8 @@ #if defined(OS_CHROMEOS) #include "chrome/browser/chromeos/gview_request_interceptor.h" +#include "chrome/browser/chromeos/mount_library.h" +#include "chrome/browser/chromeos/usb_mount_observer.h" #include "chrome/browser/views/tabs/tab_overview_message_listener.h" #endif @@ -341,6 +343,14 @@ bool LaunchBrowser(const CommandLine& command_line, Profile* profile, if (parsed_command_line.HasSwitch(switches::kEnableGView)) { chromeos::GViewRequestInterceptor::GetGViewRequestInterceptor(); } + if (process_startup) { + // TODO(dhg): Try to make this just USBMountObserver::Get()->set_profile + // and have the constructor take care of everything else. + chromeos::MountLibrary* lib = chromeos::MountLibrary::Get(); + chromeos::USBMountObserver* observe = chromeos::USBMountObserver::Get(); + observe->set_profile(profile); + lib->AddObserver(observe); + } #endif return true; } diff --git a/chrome/browser/chromeos/mount_library.cc b/chrome/browser/chromeos/mount_library.cc new file mode 100644 index 0000000..1c99b97 --- /dev/null +++ b/chrome/browser/chromeos/mount_library.cc @@ -0,0 +1,98 @@ +// Copyright (c) 2009 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/mount_library.h" + +#include "base/message_loop.h" +#include "base/string_util.h" +#include "chrome/browser/chrome_thread.h" +#include "chrome/browser/chromeos/cros_library.h" + +// Allows InvokeLater without adding refcounting. This class is a Singleton and +// won't be deleted until it's last InvokeLater is run. +template <> +struct RunnableMethodTraits<chromeos::MountLibrary> { + void RetainCallee(chromeos::MountLibrary* obj) {} + void ReleaseCallee(chromeos::MountLibrary* obj) {} +}; + +namespace chromeos { + +// static +MountLibrary* MountLibrary::Get() { + return Singleton<MountLibrary>::get(); +} + +// static +bool MountLibrary::loaded() { + return CrosLibrary::loaded(); +} + +void MountLibrary::AddObserver(Observer* observer) { + observers_.AddObserver(observer); +} + +void MountLibrary::RemoveObserver(Observer* observer) { + observers_.RemoveObserver(observer); +} + +void MountLibrary::ParseDisks(const MountStatus& status) { + disks_.clear(); + for (int i = 0; i < status.size; i++) { + std::string path; + std::string mountpath; + if (status.disks[i].path != NULL) { + path = status.disks[i].path; + } + if (status.disks[i].mountpath != NULL) { + mountpath = status.disks[i].mountpath; + } + disks_.push_back(Disk(path, mountpath)); + } +} + +MountLibrary::MountLibrary() { + if (CrosLibrary::loaded()) { + Init(); + } else { + LOG(ERROR) << "Cros Library has not been loaded"; + } +} + +MountLibrary::~MountLibrary() { + if (CrosLibrary::loaded()) { + DisconnectMountStatus(mount_status_connection_); + } +} + +// static +void MountLibrary::MountStatusChangedHandler(void* object, + const MountStatus& status, + MountEventType evt, + const char* path) { + MountLibrary* mount = static_cast<MountLibrary*>(object); + std::string devicepath = path; + mount->ParseDisks(status); + mount->UpdateMountStatus(status, evt, devicepath); +} + +void MountLibrary::Init() { + // Getting the monitor status so that the daemon starts up. + MountStatus* mount = RetrieveMountInformation(); + FreeMountStatus(mount); + + mount_status_connection_ = MonitorMountStatus( + &MountStatusChangedHandler, this); +} + +void MountLibrary::UpdateMountStatus(const MountStatus& status, + MountEventType evt, + const std::string& path) { + // Make sure we run on UI thread. + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); + + FOR_EACH_OBSERVER(Observer, observers_, MountChanged(this, evt, path)); +} + +} // namespace chromeos diff --git a/chrome/browser/chromeos/mount_library.h b/chrome/browser/chromeos/mount_library.h new file mode 100644 index 0000000..91b6059 --- /dev/null +++ b/chrome/browser/chromeos/mount_library.h @@ -0,0 +1,91 @@ +// Copyright (c) 2009 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_MOUNT_LIBRARY_H_ +#define CHROME_BROWSER_CHROMEOS_MOUNT_LIBRARY_H_ + +#include <string> +#include <vector> + +#include "base/observer_list.h" +#include "base/singleton.h" +#include "base/time.h" +#include "third_party/cros/chromeos_mount.h" + +namespace chromeos { + +// This class handles the interaction with the ChromeOS mount library APIs. +// Classes can add themselves as observers. Users can get an instance of this +// library class like this: MountLibrary::Get(). +class MountLibrary { + public: + // Used to house an instance of each found mount device. + struct Disk { + Disk() {} + Disk(const std::string& devicepath, const std::string& mountpath) + : device_path(devicepath), + mount_path(mountpath) {} + std::string device_path; + std::string mount_path; + }; + typedef std::vector<Disk> DiskVector; + + class Observer { + public: + virtual void MountChanged(MountLibrary* obj, + MountEventType evt, + const std::string& path) = 0; + }; + + // This gets the singleton MountLibrary + static MountLibrary* Get(); + + // Returns true if the ChromeOS library was loaded. + static bool loaded(); + + void AddObserver(Observer* observer); + void RemoveObserver(Observer* observer); + + const DiskVector& disks() const { return disks_; } + + private: + friend struct DefaultSingletonTraits<MountLibrary>; + + void ParseDisks(const MountStatus& status); + + MountLibrary(); + ~MountLibrary(); + + // This method is called when there's a change in mount status. + // This method is called the UI Thread. + static void MountStatusChangedHandler(void* object, + const MountStatus& status, + MountEventType evt, + const char* path); + + // This methods starts the monitoring of mount changes. + // It should be called on the UI Thread. + void Init(); + + // Called by the handler to update the mount status. + // This will notify all the Observers. + void UpdateMountStatus(const MountStatus& status, + MountEventType evt, + const std::string& path); + + ObserverList<Observer> observers_; + + // A reference to the mount api, to allow callbacks when the mount + // status changes. + MountStatusConnection mount_status_connection_; + + // The list of disks found. + DiskVector disks_; + + DISALLOW_COPY_AND_ASSIGN(MountLibrary); +}; + +} // namespace chromeos + +#endif // CHROME_BROWSER_CHROMEOS_MOUNT_LIBRARY_H_ diff --git a/chrome/browser/chromeos/usb_mount_observer.cc b/chrome/browser/chromeos/usb_mount_observer.cc new file mode 100644 index 0000000..177aaf1 --- /dev/null +++ b/chrome/browser/chromeos/usb_mount_observer.cc @@ -0,0 +1,91 @@ +// Copyright (c) 2009 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/browser.h" +#include "chrome/browser/browser_window.h" +#include "chrome/browser/chromeos/usb_mount_observer.h" + +namespace chromeos { + +void USBMountObserver::Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details) { + DCHECK(type == NotificationType::BROWSER_CLOSED); + for (BrowserIterator i = browsers_.begin(); i != browsers_.end(); + ++i) { + if (Source<Browser>(source).ptr() == i->browser) { + browsers_.erase(i); + registrar_.Remove(this, + NotificationType::BROWSER_CLOSED, + source); + return; + } + } +} + +void USBMountObserver::MountChanged(chromeos::MountLibrary* obj, + chromeos::MountEventType evt, + const std::string& path) { + if (evt == chromeos::DISK_ADDED) { + // Return since disk added doesn't mean anything until + // its mounted, which is a change event. + } else if (evt == chromeos::DISK_REMOVED) { + RemoveBrowserFromVector(path); + } else if (evt == chromeos::DISK_CHANGED) { + BrowserIterator iter = FindBrowserForPath(path); + if (iter == browsers_.end()) { + // We don't currently have this one, so it must have been + // mounted + const chromeos::MountLibrary::DiskVector& disks = obj->disks(); + for (size_t i = 0; i < disks.size(); ++i) { + if (disks[i].device_path == path) { + if (!disks[i].mount_path.empty()) { + Browser* browser = Browser::CreateForPopup(profile_); + std::string url = "chrome://filebrowse#"; + url += disks[i].mount_path; + browser->AddTabWithURL( + GURL(url), GURL(), PageTransition::START_PAGE, + true, -1, false, NULL); + browser->window()->SetBounds(gfx::Rect(0, 0, 250, 300)); + registrar_.Add(this, + NotificationType::BROWSER_CLOSED, + Source<Browser>(browser)); + browser->window()->Show(); + BrowserWithPath new_browser; + new_browser.browser = browser; + new_browser.device_path = disks[i].device_path; + browsers_.push_back(new_browser); + } + return; + } + } + } + } +} + +USBMountObserver::BrowserIterator USBMountObserver::FindBrowserForPath( + const std::string& path) { + for (BrowserIterator i = browsers_.begin();i != browsers_.end(); + ++i) { + if (i->device_path == path) { + return i; + } + } + return browsers_.end(); +} + +void USBMountObserver::RemoveBrowserFromVector(const std::string& path) { + BrowserIterator i = FindBrowserForPath(path); + if (i != browsers_.end()) { + registrar_.Remove(this, + NotificationType::BROWSER_CLOSED, + Source<Browser>(i->browser)); + if (i->browser->window()) { + i->browser->window()->Close(); + } + browsers_.erase(i); + } +} + +} // namespace chromeos diff --git a/chrome/browser/chromeos/usb_mount_observer.h b/chrome/browser/chromeos/usb_mount_observer.h new file mode 100644 index 0000000..c6cb2b9 --- /dev/null +++ b/chrome/browser/chromeos/usb_mount_observer.h @@ -0,0 +1,61 @@ +// Copyright (c) 2009 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_USB_MOUNT_OBSERVER_H_ +#define CHROME_BROWSER_CHROMEOS_USB_MOUNT_OBSERVER_H_ + +#include <string> +#include <vector> + +#include "chrome/browser/chromeos/mount_library.h" +#include "chrome/common/notification_observer.h" +#include "chrome/common/notification_source.h" +#include "chrome/common/notification_type.h" +#include "chrome/common/notification_registrar.h" + +class Browser; +class Profile; + +namespace chromeos { // NOLINT + +// Used to monitor mount changes and popup a new window when +// a new mounted usb device is found. +class USBMountObserver : public chromeos::MountLibrary::Observer, + public NotificationObserver { + public: + struct BrowserWithPath { + Browser* browser; + std::string device_path; + }; + + USBMountObserver() {} + ~USBMountObserver() {} + + void set_profile(Profile* profile) { profile_ = profile; } + + static USBMountObserver* Get() { + return Singleton<USBMountObserver>::get(); + } + void Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details); + + void MountChanged(chromeos::MountLibrary* obj, + chromeos::MountEventType evt, + const std::string& path); + private: + typedef std::vector<BrowserWithPath>::iterator BrowserIterator; + BrowserIterator FindBrowserForPath(const std::string& path); + + void RemoveBrowserFromVector(const std::string& path); + + Profile* profile_; + std::vector<BrowserWithPath> browsers_; + NotificationRegistrar registrar_; + + DISALLOW_COPY_AND_ASSIGN(USBMountObserver); +}; + +} // namespace chromeos +#endif // CHROME_BROWSER_CHROMEOS_USB_MOUNT_OBSERVER_H_ diff --git a/chrome/browser/resources/filebrowse.html b/chrome/browser/resources/filebrowse.html index 3c85726..c3f40a5 100644 --- a/chrome/browser/resources/filebrowse.html +++ b/chrome/browser/resources/filebrowse.html @@ -2,32 +2,254 @@ <html i18n-values="dir:textdirection;"> <head> <meta charset="utf-8"> -<title i18n-content="title"></title> +<title>Content Browser</title> <style type="text/css"> +div.header { + border-bottom: 1px solid #006; + padding: 8px; + margin: 0; + width: 100%; + left: 0; + top: 0; + min-height: 26px; + position: absolute; + -webkit-box-sizing: border-box; + box-sizing: border-box; + background-image: -webkit-gradient(linear, 0% 0%, 0% 90%, from(rgb(239, 242, 249)), to(rgba(201, 212, 245, 1))); + border-bottom-color: #999; + border-bottom-width: 1px; + color: black; +} + +a.iconlink { + display: block; + font-family: helvetica; + font-weight: bold; + font-size: 11px; + color: white; + text-decoration: none; +} + +a.iconlink img { + margin-bottom: 5px; +} + +ul.filebrowselist { + list-style-type: none; + margin: 0; + padding: 0; + position: relative; +} + +li.filebrowserow div.icon { + float: left; + margin-left: -44px; + margin-top: -3px; + display: inline + position: relative; + width: 17px; + height: 17px; + background-repeat: no-repeat; +} + +.rightarrow { + margin-top: 2px; + position: absolute; + right: 0; + top: 5px; + height: 100%; + width: 10px; +} + +li.filebrowserow { + border-bottom: 1px solid #f7f7f7; + padding: 8px 5px 5px 54px; + overflow: hidden; + font-size:.8em; + font-family: helvetica; + position: relative; +} + +li.filebrowserow span.name { + margin-top: 10px; + margin-left: -22px; + position: relative; +} + +div.title { + text-align: center; + position: relative; + font-size: 18px; + padding-top: 10px; +} + +div.controlbutton { + width: 20px; + display:inline; + position: absolute; + z-index:9999; + border:1px solid #abb6ce; + background-color: #f5f7fc; + padding-left: 7px; + padding-top: 4px; + padding-bottom: 4px; + padding-right: 7px; + height: 20px; +} + +div.iconmedia { + background: url('../../app/theme/icon_media.png'); +} + +div.iconfolder { + background: url('../../app/theme/icon_folder.png'); +} + +div.iconfile { + background: url('../../app/theme/icon_file.png'); +} + +div.iconphoto { + background: url('../../app/theme/icon_photo.png'); +} + +div.iconmusic { + background: url('../../app/theme/icon_media.png'); +} + +div.backbutton { + -webkit-border-top-left-radius: 5px; + -webkit-border-bottom-left-radius: 5px; + left: 10px; + top: 10px +} + +div.fwdbutton { + -webkit-border-top-right-radius: 5px; + -webkit-border-bottom-right-radius: 5px; + left: 45px; + top: 10px; +} + +div.playbackcontainer { + top: 0; + left: 0; + position: absolute; + width: 100%; + height: 100%; + background: black; +} + +div.container { + top: 50px; + position: absolute; + width: 95%; +} + +.mediacontainer { + top: 0; + left: 0; + position: absolute; + width: 100%; + height: 100%; +} + +a:hover { + color: #3874be; + text-decoration: underline; + display: block; +} + </style> -<link rel="icon" href="../../app/theme/history_favicon.png"> <script src="local_strings.js"></script> <script> -/////////////////////////////////////////////////////////////////////////////// -// Globals: -var RESULTS_PER_PAGE = 150; -var MAX_SEARCH_DEPTH_MONTHS = 18; -// Amount of time between pageviews that we consider a 'break' in browsing, -// measured in milliseconds. -var BROWSING_GAP_TIME = 15 * 60 * 1000; -function $(o) {return document.getElementById(o);} -function encodeURIForCSS(uri) { - // CSS uris need to have '(' and ')' escaped. - return uri.replace(/\(/g, "\\(").replace(/\)/g, "\\)"); +function $(o) { + return document.getElementById(o); +} + +var pathArray = []; +var currentNode = -1; + +var goBackInList = function() { + if (currentNode > 0) { + currentNode--; + getDataForPath(pathArray[currentNode]); + } +}; + +var goForwardInList = function() { + if (currentNode < (pathArray.length - 1)) { + currentNode++; + getDataForPath(pathArray[currentNode]); + } +}; + +function fileBrowseResult(info, results) { + if (info.call == 'getRoots' || info.call == 'getChildren') { + currentNode++; + createNewList(' ', results); + } } -var localStrings; -var pageState; -var results_; +var pathIsVideoFile = function(path) { + return /\.(mp4|ogg|mpg|avi)$/i.test(path); +}; + +var pathIsAudioFile = function(path) { + return /\.(mp3|m4a)$/i.test(path); +}; + +var pathIsImageFile = function(path) { + return /\.(jpg|png)$/i.test(path); +}; + + +var setUpForPlayback = function(path) { + mediapath = 'file://' + path; + var header = $('header'); + document.body.removeChild(header); + var main = $('main'); + main.className = 'playbackcontainer'; + var elementType; + if (pathIsVideoFile(path)) { + elementType = 'video'; + } else if (pathIsAudioFile(path)) { + elementType = 'audio'; + } else { + // close because we can't deal with this. + return; + } + var element = document.createElement(elementType); + element.className = 'mediacontainer'; + element.autoplay = true; + element.controls = true; + element.src = mediapath; + main.appendChild(element); +}; + +var getClassForPath = function(path, isDirectory) { + if (isDirectory) { + return 'icon iconfolder'; + } else if (pathIsImageFile(path)) { + return 'icon iconphoto'; + } else if (pathIsVideoFile(path)) { + return 'icon iconmedia'; + } else if (pathIsAudioFile(path)) { + return 'icon iconmusic'; + } + return 'icon iconfile'; +}; +var getDataForPath = function(path) { + if (path == 'roots' ) { + chrome.send('getRoots', []); + } else { + chrome.send('getChildren', [path]); + } +}; /////////////////////////////////////////////////////////////////////////////// // Document Functions: @@ -35,65 +257,114 @@ var results_; * Window onload handler, sets up the page. */ function load() { + if (document.location.href.indexOf('#') != -1) { + var currentpathArray = document.location.href.split('#'); + var path = currentpathArray[1]; + if (pathIsVideoFile(path) || pathIsAudioFile(path)) { + setUpForPlayback(path); + } else { + pathArray.push(path); + getDataForPath(path); + } + } else { + pathArray.push('roots'); + getDataForPath('roots'); + } +}; - localStrings = new LocalStrings(); - try { - chrome.send('getRoots', []); - } catch (e) { - //TODO: Do something smart here. +var decend = function(path) { + if (pathArray.length <currentNode) { + pathArray = pathArray.slice(0, currentNode); } -} + pathArray.push(path); + getDataForPath(path); +}; -////////////////////////////////////////////////////////////////////////////// -// Helper functions +function playMediaFile(path) { + // For now open it up using the filebrowser, maybe in the future just open with + // a file:// + window.open('chrome://filebrowse#'+path, 'MediaPlayer', 'menubar=0,resizable=0,width=400,height=300'); +}; -var browseFile = function(path) { +function showImage(path) { + window.open('file://' + path, 'View Image', 'width=800,height=600'); +}; - try { - chrome.send('getChildren', [path]); - } catch (e) { - //TODO: Do something smart. - alert('uh-oh'); +// TODO(dhg): Do not use javascript: href, use onclick instead +var createHrefForItem = function(path, isDirectory) { + if (isDirectory) { + return 'javascript:decend("'+path+'");'; + } if (pathIsAudioFile(path)) { + return 'javascript:playMediaFile("'+path+'");'; + } if (pathIsVideoFile(path)) { + return 'javascript:playMediaFile("'+path+'");'; + } if (pathIsImageFile(path)) { + return 'javascript:showImage("'+path+'");'; + } else { + return ''; } }; -/////////////////////////////////////////////////////////////////////////////// -// Chrome callbacks: -/** - * Our callback for when a system is completed. - */ -function fileBrowseResult(info, results) { - try { - var output = ""; - if (info.call == "getRoots" || info.call == "getChildren") { - for (var x=0; x < results.length; x++) { - if (results[x].isDirectory) { - output += "<a href='javascript:browseFile(\""+results[x].path+"\");'>"; - output += results[x].title; - output += "</a><br/>"; - } else { - output += results[x].title; - output += "<br/>"; - } - } - } - results_ = results; - var main = $('main'); - main.innerHTML = output; - } catch (e) { - alert(e); - } -} -</script> -<link rel="stylesheet" href="dom_ui.css"> -<style> +var createNewItem = function(title, path, isDirectory) { + var element = document.createElement('li'); + element.className = 'filebrowserow'; -</style> -</head> -<body onload="load();" i18n-values=".style.fontFamily:fontfamily;.style.fontSize:fontsize"> -<div class="header"></div> -<div class="main" id="main"></div> -<div class="footer"> -</div> + var link = document.createElement('a'); + link.className = 'rowlink'; + link.href = createHrefForItem(path, isDirectory); + + var icon = document.createElement('div'); + icon.className = getClassForPath(path, isDirectory); + link.appendChild(icon); + + var span = document.createElement('span'); + span.className = 'name'; + span.textContent = title; + link.appendChild(span); + + element.appendChild(link); + if (isDirectory) { + var rightarrow = document.createElement('div'); + rightarrow.align = 'right'; + rightarrow.innerHTML = '»'; + rightarrow.className = 'rightarrow'; + element.appendChild(rightarrow); + } + + return element; +}; + +var clearChildren = function(element) { + element.innerHTML = ''; +}; + +var createNewList = function(title, results) { + var list = document.createElement('ul'); + list.className = 'filebrowselist'; + var header = $('currenttitle'); + header.innerHTML = title; + for (var x=0; x < results.length; x++) { + var element = createNewItem(results[x].title, + results[x].path, + results[x].isDirectory); + list.appendChild(element); + } + var main = $('main'); + clearChildren(main); + main.appendChild(list); +}; + +</script> +<body onload="load();"> +<div id='header' class='header'> + <div id='back' class='backbutton controlbutton' onclick='goBackInList();return false;'> + <img src="../../app/theme/filebrowse_back.png" width='100%' height='100%'> + </div> + <div id='fwd' class='fwdbutton controlbutton' onclick='goForwardInList();return false;'> + <img src="../../app/theme/filebrowse_forward.png" width='100%' height='100%'> + </div> + <div id='currenttitle' class='title'></div> +</div><br> +<div id='main' class='container'></div> </body> </html> diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp index 36a420f..bc4711d 100755 --- a/chrome/chrome.gyp +++ b/chrome/chrome.gyp @@ -995,6 +995,8 @@ 'browser/chromeos/gview_request_interceptor.h', 'browser/chromeos/main_menu.cc', 'browser/chromeos/main_menu.h', + 'browser/chromeos/mount_library.cc', + 'browser/chromeos/mount_library.h', 'browser/chromeos/network_library.cc', 'browser/chromeos/network_library.h', 'browser/chromeos/network_menu_button.cc', @@ -1027,6 +1029,8 @@ 'browser/chromeos/status_area_view.h', 'browser/chromeos/synaptics_library.cc', 'browser/chromeos/synaptics_library.h', + 'browser/chromeos/usb_mount_observer.cc', + 'browser/chromeos/usb_mount_observer.h', 'browser/chromeos/version_loader.cc', 'browser/chromeos/version_loader.h', 'browser/cocoa/about_ipc_bridge.h', |