summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/chromeos/extensions/file_manager/action_choice_dialog.cc93
-rw-r--r--chrome/browser/chromeos/extensions/file_manager/action_choice_dialog.h28
-rw-r--r--chrome/browser/chromeos/extensions/file_manager/file_manager_util.cc67
-rw-r--r--chrome/browser/chromeos/extensions/file_manager/file_manager_util.h6
-rw-r--r--chrome/chrome_browser_chromeos.gypi2
5 files changed, 123 insertions, 73 deletions
diff --git a/chrome/browser/chromeos/extensions/file_manager/action_choice_dialog.cc b/chrome/browser/chromeos/extensions/file_manager/action_choice_dialog.cc
new file mode 100644
index 0000000..53323ae
--- /dev/null
+++ b/chrome/browser/chromeos/extensions/file_manager/action_choice_dialog.cc
@@ -0,0 +1,93 @@
+// Copyright 2013 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/file_manager/action_choice_dialog.h"
+
+#include "ash/shell.h"
+#include "base/files/file_path.h"
+#include "chrome/browser/chromeos/extensions/file_manager/app_id.h"
+#include "chrome/browser/chromeos/extensions/file_manager/fileapi_util.h"
+#include "chrome/browser/chromeos/extensions/file_manager/url_util.h"
+#include "chrome/browser/extensions/extension_service.h"
+#include "chrome/browser/extensions/extension_system.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/profiles/profile_manager.h"
+#include "chrome/browser/ui/browser.h"
+#include "chrome/browser/ui/browser_iterator.h"
+#include "chrome/browser/ui/browser_window.h"
+#include "chrome/browser/ui/extensions/application_launch.h"
+#include "chrome/browser/ui/tabs/tab_strip_model.h"
+#include "content/public/browser/web_contents.h"
+#include "ui/gfx/screen.h"
+
+namespace file_manager {
+namespace util {
+namespace {
+
+// Finds a browser instance showing the target URL. Returns NULL if not
+// found.
+Browser* FindBrowserForUrl(GURL target_url) {
+ for (chrome::BrowserIterator it; !it.done(); it.Next()) {
+ Browser* browser = *it;
+ TabStripModel* tab_strip = browser->tab_strip_model();
+ for (int idx = 0; idx < tab_strip->count(); idx++) {
+ content::WebContents* web_contents = tab_strip->GetWebContentsAt(idx);
+ const GURL& url = web_contents->GetLastCommittedURL();
+ if (url == target_url)
+ return browser;
+ }
+ }
+ return NULL;
+}
+
+} // namespace
+
+void OpenActionChoiceDialog(const base::FilePath& file_path,
+ bool advanced_mode) {
+ const int kDialogWidth = 394;
+ // TODO(dgozman): remove 50, which is a title height once popup window
+ // will have no title.
+ const int kDialogHeight = 316 + 50;
+
+ Profile* profile = ProfileManager::GetDefaultProfileOrOffTheRecord();
+
+ base::FilePath virtual_path;
+ if (!ConvertAbsoluteFilePathToRelativeFileSystemPath(
+ profile, kFileManagerAppId, file_path, &virtual_path))
+ return;
+ GURL dialog_url = GetActionChoiceUrl(virtual_path, advanced_mode);
+
+ const gfx::Size screen = ash::Shell::GetScreen()->GetPrimaryDisplay().size();
+ const gfx::Rect bounds((screen.width() - kDialogWidth) / 2,
+ (screen.height() - kDialogHeight) / 2,
+ kDialogWidth,
+ kDialogHeight);
+
+ Browser* browser = FindBrowserForUrl(dialog_url);
+
+ if (browser) {
+ browser->window()->Show();
+ return;
+ }
+
+ ExtensionService* service = extensions::ExtensionSystem::Get(profile)->
+ extension_service();
+ if (!service)
+ return;
+
+ const extensions::Extension* extension =
+ service->GetExtensionById(kFileManagerAppId, false);
+ if (!extension)
+ return;
+
+ chrome::AppLaunchParams params(profile, extension,
+ extension_misc::LAUNCH_WINDOW,
+ NEW_FOREGROUND_TAB);
+ params.override_url = dialog_url;
+ params.override_bounds = bounds;
+ chrome::OpenApplication(params);
+}
+
+} // namespace util
+} // namespace file_manager
diff --git a/chrome/browser/chromeos/extensions/file_manager/action_choice_dialog.h b/chrome/browser/chromeos/extensions/file_manager/action_choice_dialog.h
new file mode 100644
index 0000000..b95f86c
--- /dev/null
+++ b/chrome/browser/chromeos/extensions/file_manager/action_choice_dialog.h
@@ -0,0 +1,28 @@
+// Copyright 2013 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.
+//
+// This file provides the action choice dialog. The dialog is shown when an
+// removable drive, such as an SD card, is inserted, to ask the user what to
+// do with the drive (ex. open the file manager, or open some other app).
+
+#ifndef CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_ACTION_CHOICE_DIALOG_H_
+#define CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_ACTION_CHOICE_DIALOG_H_
+
+namespace base {
+class FilePath;
+}
+
+namespace file_manager {
+namespace util {
+
+// Opens an action choice dialog for a removable drive.
+// One of the actions is opening the File Manager. Passes |advanced_mode|
+// flag to the dialog. If it is enabled, then auto-choice gets disabled.
+void OpenActionChoiceDialog(const base::FilePath& file_path,
+ bool advanced_mode);
+
+} // namespace util
+} // namespace file_manager
+
+#endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_ACTION_CHOICE_DIALOG_H_
diff --git a/chrome/browser/chromeos/extensions/file_manager/file_manager_util.cc b/chrome/browser/chromeos/extensions/file_manager/file_manager_util.cc
index d5a9a95..48702c4 100644
--- a/chrome/browser/chromeos/extensions/file_manager/file_manager_util.cc
+++ b/chrome/browser/chromeos/extensions/file_manager/file_manager_util.cc
@@ -4,7 +4,6 @@
#include "chrome/browser/chromeos/extensions/file_manager/file_manager_util.h"
-#include "ash/shell.h"
#include "base/bind.h"
#include "base/command_line.h"
#include "base/logging.h"
@@ -33,13 +32,10 @@
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_finder.h"
-#include "chrome/browser/ui/browser_iterator.h"
#include "chrome/browser/ui/browser_tabstrip.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/extensions/application_launch.h"
-#include "chrome/browser/ui/host_desktop.h"
#include "chrome/browser/ui/simple_message_box.h"
-#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/extensions/api/file_browser_handlers/file_browser_handler.h"
@@ -49,7 +45,6 @@
#include "content/public/browser/plugin_service.h"
#include "content/public/browser/storage_partition.h"
#include "content/public/browser/user_metrics.h"
-#include "content/public/browser/web_contents.h"
#include "content/public/common/pepper_plugin_info.h"
#include "content/public/common/webplugininfo.h"
#include "grit/generated_resources.h"
@@ -57,7 +52,6 @@
#include "net/base/mime_util.h"
#include "net/base/net_util.h"
#include "ui/base/l10n/l10n_util.h"
-#include "ui/gfx/screen.h"
#include "webkit/browser/fileapi/file_system_backend.h"
#include "webkit/browser/fileapi/file_system_context.h"
#include "webkit/browser/fileapi/file_system_operation_runner.h"
@@ -262,20 +256,6 @@ void OpenFileManagerWithInternalActionId(const base::FilePath& file_path,
ExecuteFileTaskForUrl(profile, task, url);
}
-Browser* GetBrowserForUrl(GURL target_url) {
- for (chrome::BrowserIterator it; !it.done(); it.Next()) {
- Browser* browser = *it;
- TabStripModel* tab_strip = browser->tab_strip_model();
- for (int idx = 0; idx < tab_strip->count(); idx++) {
- content::WebContents* web_contents = tab_strip->GetWebContentsAt(idx);
- const GURL& url = web_contents->GetLastCommittedURL();
- if (url == target_url)
- return browser;
- }
- }
- return NULL;
-}
-
// Opens the file specified by |file_path| and |url| with a file handler,
// preferably the default handler for the type of the file. Returns false if
// no file handler is found.
@@ -497,53 +477,6 @@ void OpenRemovableDrive(const base::FilePath& file_path) {
OpenFileManagerWithInternalActionId(file_path, "auto-open");
}
-void OpenActionChoiceDialog(const base::FilePath& file_path,
- bool advanced_mode) {
- const int kDialogWidth = 394;
- // TODO(dgozman): remove 50, which is a title height once popup window
- // will have no title.
- const int kDialogHeight = 316 + 50;
-
- Profile* profile = ProfileManager::GetDefaultProfileOrOffTheRecord();
-
- base::FilePath virtual_path;
- if (!ConvertAbsoluteFilePathToRelativeFileSystemPath(
- profile, kFileManagerAppId, file_path, &virtual_path))
- return;
- GURL dialog_url = GetActionChoiceUrl(virtual_path, advanced_mode);
-
- const gfx::Size screen = ash::Shell::GetScreen()->GetPrimaryDisplay().size();
- const gfx::Rect bounds((screen.width() - kDialogWidth) / 2,
- (screen.height() - kDialogHeight) / 2,
- kDialogWidth,
- kDialogHeight);
-
- Browser* browser = GetBrowserForUrl(dialog_url);
-
- if (browser) {
- browser->window()->Show();
- return;
- }
-
- ExtensionService* service = extensions::ExtensionSystem::Get(
- profile ? profile : ProfileManager::GetDefaultProfileOrOffTheRecord())->
- extension_service();
- if (!service)
- return;
-
- const extensions::Extension* extension =
- service->GetExtensionById(kFileManagerAppId, false);
- if (!extension)
- return;
-
- chrome::AppLaunchParams params(profile, extension,
- extension_misc::LAUNCH_WINDOW,
- NEW_FOREGROUND_TAB);
- params.override_url = dialog_url;
- params.override_bounds = bounds;
- chrome::OpenApplication(params);
-}
-
void OpenItem(const base::FilePath& file_path) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
diff --git a/chrome/browser/chromeos/extensions/file_manager/file_manager_util.h b/chrome/browser/chromeos/extensions/file_manager/file_manager_util.h
index b41bf03..681ef4c 100644
--- a/chrome/browser/chromeos/extensions/file_manager/file_manager_util.h
+++ b/chrome/browser/chromeos/extensions/file_manager/file_manager_util.h
@@ -31,12 +31,6 @@ string16 GetTitleFromType(ui::SelectFileDialog::Type type);
// unmount.
void OpenRemovableDrive(const base::FilePath& file_path);
-// Opens an action choice dialog for an external drive.
-// One of the actions is opening the File Manager. Passes |advanced_mode|
-// flag to the dialog. If it is enabled, then auto-choice gets disabled.
-void OpenActionChoiceDialog(const base::FilePath& file_path,
- bool advanced_mode);
-
// Opens an item (file or directory). If the target is a directory, the
// directory will be opened in the file manager. If the target is a file, the
// file will be opened using a file handler, a file browser handler, or the
diff --git a/chrome/chrome_browser_chromeos.gypi b/chrome/chrome_browser_chromeos.gypi
index 2beaf58..8981057 100644
--- a/chrome/chrome_browser_chromeos.gypi
+++ b/chrome/chrome_browser_chromeos.gypi
@@ -321,6 +321,8 @@
'browser/chromeos/extensions/external_cache.h',
'browser/chromeos/extensions/external_pref_cache_loader.cc',
'browser/chromeos/extensions/external_pref_cache_loader.h',
+ 'browser/chromeos/extensions/file_manager/action_choice_dialog.cc',
+ 'browser/chromeos/extensions/file_manager/action_choice_dialog.h',
'browser/chromeos/extensions/file_manager/app_id.h',
'browser/chromeos/extensions/file_manager/desktop_notifications.cc',
'browser/chromeos/extensions/file_manager/desktop_notifications.h',