diff options
author | kmadhusu@chromium.org <kmadhusu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-26 23:34:29 +0000 |
---|---|---|
committer | kmadhusu@chromium.org <kmadhusu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-26 23:34:29 +0000 |
commit | bd52a98b4ef0149a544c45a3dbf870ce3f384688 (patch) | |
tree | f6b503429a143d22c3fbf07ec4a4f89e98a03a63 /chrome | |
parent | 080473a3920a4e61323637fa05024069fccbf48d (diff) | |
download | chromium_src-bd52a98b4ef0149a544c45a3dbf870ce3f384688.zip chromium_src-bd52a98b4ef0149a544c45a3dbf870ce3f384688.tar.gz chromium_src-bd52a98b4ef0149a544c45a3dbf870ce3f384688.tar.bz2 |
Add ability to dispatch an intent on a device attached event.
BUG=110400
TEST=none
Review URL: https://chromiumcodereview.appspot.com/10578024
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@144322 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/extensions/api/app/app_api.cc | 3 | ||||
-rw-r--r-- | chrome/browser/intents/device_attached_intent_source.cc | 62 | ||||
-rw-r--r-- | chrome/browser/intents/device_attached_intent_source.h | 43 | ||||
-rw-r--r-- | chrome/browser/ui/browser.cc | 6 | ||||
-rw-r--r-- | chrome/browser/ui/browser.h | 2 | ||||
-rw-r--r-- | chrome/chrome_browser.gypi | 2 |
6 files changed, 118 insertions, 0 deletions
diff --git a/chrome/browser/extensions/api/app/app_api.cc b/chrome/browser/extensions/api/app/app_api.cc index 7dc2fb9..408ecd0 100644 --- a/chrome/browser/extensions/api/app/app_api.cc +++ b/chrome/browser/extensions/api/app/app_api.cc @@ -183,6 +183,9 @@ void AppEventRouter::DispatchOnLaunchedEventWithWebIntent( base::Int64ToString(web_intent_data.blob_length)); args.Append(intent_data); break; + default: + NOTREACHED(); + break; } std::string json_args; base::JSONWriter::Write(&args, &json_args); diff --git a/chrome/browser/intents/device_attached_intent_source.cc b/chrome/browser/intents/device_attached_intent_source.cc new file mode 100644 index 0000000..de9bace --- /dev/null +++ b/chrome/browser/intents/device_attached_intent_source.cc @@ -0,0 +1,62 @@ +// Copyright (c) 2012 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/intents/device_attached_intent_source.h" + +#include "base/file_path.h" +#include "base/utf_string_conversions.h" +#include "chrome/browser/ui/browser.h" +#include "chrome/browser/ui/browser_window.h" +#include "content/public/browser/web_intents_dispatcher.h" +#include "content/public/browser/web_contents_delegate.h" +#include "webkit/fileapi/isolated_context.h" +#include "webkit/glue/web_intent_data.h" + +using base::SystemMonitor; +using content::WebContentsDelegate; + +DeviceAttachedIntentSource::DeviceAttachedIntentSource( + Browser* browser, WebContentsDelegate* delegate) + : browser_(browser), delegate_(delegate) { + SystemMonitor* sys_monitor = SystemMonitor::Get(); + if (sys_monitor) + sys_monitor->AddDevicesChangedObserver(this); +} + +DeviceAttachedIntentSource::~DeviceAttachedIntentSource() { + SystemMonitor* sys_monitor = SystemMonitor::Get(); + if (sys_monitor) + sys_monitor->RemoveDevicesChangedObserver(this); +} + +void DeviceAttachedIntentSource::OnMediaDeviceAttached( + const base::SystemMonitor::DeviceIdType& id, + const std::string& name, + const FilePath& device_path) { + if (!browser_->window()->IsActive()) + return; + + // Sanity checks for |device_path|. + if (!device_path.IsAbsolute() || device_path.ReferencesParent() || + device_path.BaseName().IsAbsolute() || device_path.BaseName().empty()) { + return; + } + + // Register device path as an isolated file system. + std::set<FilePath> fileset; + fileset.insert(device_path); + const std::string filesystem_id = + fileapi::IsolatedContext::GetInstance()-> + RegisterIsolatedFileSystem(fileset); + CHECK(!filesystem_id.empty()); + webkit_glue::WebIntentData intent( + ASCIIToUTF16("chrome-extension://attach"), + ASCIIToUTF16("chrome-extension://filesystem"), + device_path, + filesystem_id); + + content::WebIntentsDispatcher* dispatcher = + content::WebIntentsDispatcher::Create(intent); + delegate_->WebIntentDispatch(NULL, dispatcher); +} diff --git a/chrome/browser/intents/device_attached_intent_source.h b/chrome/browser/intents/device_attached_intent_source.h new file mode 100644 index 0000000..e0ab1ef --- /dev/null +++ b/chrome/browser/intents/device_attached_intent_source.h @@ -0,0 +1,43 @@ +// Copyright (c) 2012 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_INTENTS_DEVICE_ATTACHED_INTENT_SOURCE_H_ +#define CHROME_BROWSER_INTENTS_DEVICE_ATTACHED_INTENT_SOURCE_H_ + +#include "base/system_monitor/system_monitor.h" + +class FilePath; +class Browser; + +namespace content { +class WebContentsDelegate; +} + +// Listens for media devices attached to the system. When such are detected, +// translates the notification into a Web Intents dispatch. +// The intent payload is: +// action = "chrome-extension://attach" +// type = "chrome-extension://filesystem" +// root_path = the File Path at which the device is accessible +// filesystem_id = registered isolated file system identifier +class DeviceAttachedIntentSource + : public base::SystemMonitor::DevicesChangedObserver { + public: + explicit DeviceAttachedIntentSource(Browser* browser, + content::WebContentsDelegate* delegate); + virtual ~DeviceAttachedIntentSource(); + + // DevicesChangedObserver + virtual void OnMediaDeviceAttached( + const base::SystemMonitor::DeviceIdType& id, + const std::string& name, + const FilePath& path) OVERRIDE; + + private: + // Weak pointer to browser to which intents will be dispatched. + Browser* browser_; + content::WebContentsDelegate* delegate_; +}; + +#endif // CHROME_BROWSER_INTENTS_DEVICE_ATTACHED_INTENT_SOURCE_H_ diff --git a/chrome/browser/ui/browser.cc b/chrome/browser/ui/browser.cc index 478acf7..211be2f 100644 --- a/chrome/browser/ui/browser.cc +++ b/chrome/browser/ui/browser.cc @@ -341,6 +341,7 @@ Browser::Browser(Type type, Profile* profile) synced_window_delegate_( new BrowserSyncedWindowDelegate(this))), bookmark_bar_state_(BookmarkBar::HIDDEN), + device_attached_intent_source_(this, this), window_has_shown_(false) { tab_strip_model_->AddObserver(this); @@ -2527,6 +2528,11 @@ void Browser::WebIntentDispatch( UMA_HISTOGRAM_COUNTS("WebIntents.Dispatch", 1); + if (!web_contents) { + // Intent is system-caused and the picker will show over the currently + // active web contents. + web_contents = GetActiveWebContents(); + } TabContents* tab_contents = TabContents::FromWebContents(web_contents); tab_contents->web_intent_picker_controller()->SetIntentsDispatcher( intents_dispatcher); diff --git a/chrome/browser/ui/browser.h b/chrome/browser/ui/browser.h index 94cc290..a067765 100644 --- a/chrome/browser/ui/browser.h +++ b/chrome/browser/ui/browser.h @@ -22,6 +22,7 @@ #include "chrome/browser/event_disposition.h" #include "chrome/browser/extensions/extension_tab_helper_delegate.h" #include "chrome/browser/instant/instant_delegate.h" +#include "chrome/browser/intents/device_attached_intent_source.h" #include "chrome/browser/prefs/pref_change_registrar.h" #include "chrome/browser/prefs/pref_member.h" #include "chrome/browser/sessions/session_id.h" @@ -1241,6 +1242,7 @@ class Browser : public TabStripModelDelegate, scoped_ptr<InstantUnloadHandler> instant_unload_handler_; BookmarkBar::State bookmark_bar_state_; + DeviceAttachedIntentSource device_attached_intent_source_; scoped_refptr<FullscreenController> fullscreen_controller_; diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index f566919..3ddc8a0 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -1305,6 +1305,8 @@ 'browser/intents/cws_intents_registry.cc', 'browser/intents/cws_intents_registry.h', 'browser/intents/cws_intents_registry_factory.cc', + 'browser/intents/device_attached_intent_source.cc', + 'browser/intents/device_attached_intent_source.h', 'browser/intents/cws_intents_registry_factory.h', 'browser/intents/default_web_intent_service.cc', 'browser/intents/default_web_intent_service.h', |