summaryrefslogtreecommitdiffstats
path: root/win8/metro_driver
diff options
context:
space:
mode:
authorananta@chromium.org <ananta@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-19 17:44:24 +0000
committerananta@chromium.org <ananta@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-19 17:44:24 +0000
commit25d0eddc26905d8a5e22de980436f73924b32438 (patch)
tree79095ef033b5666d4079fdadb2ceedec1e720cf1 /win8/metro_driver
parent4a17172f8fa12506af298e5f017f991162da2c29 (diff)
downloadchromium_src-25d0eddc26905d8a5e22de980436f73924b32438.zip
chromium_src-25d0eddc26905d8a5e22de980436f73924b32438.tar.gz
chromium_src-25d0eddc26905d8a5e22de980436f73924b32438.tar.bz2
Added support for displaying the select folder picker in Chrome ASH on Windows 8.
The current behavior is that the select folder picker displays in desktop mode even when when performed in ASH. Fixes are as below:- 1. In the Chrome browser added plumbing in the SelectFileDialogImpl class to forward this operation of to the metro viewer process via the newly added function HandedSelectFolder which lives in the aura namespace in the remote_window_host_win.cc file. 2. In the metro viewer code added a new class FolderPickerSession which provides the functionality for displaying the metro select folder picker and returning the results from the same. 3. The following IPC messages provide the necessary functionality to funnel the request and the result between the browser and the metro viewer process. MetroViewerHostMsg_DisplaySelectFolder MetroViewerHostMsg_SelectFolderDone I also added code to save away the metro root window in the RemoteRootWindowHostWin class when we receive the MetroViewerHostMsg_SetTargetSurface IPC from the viewer process. We return this window in the RemoteRootWindowHostWin::GetAcceleratedWidget function. This change although not needed for this CL seems correct. BUG=230087 R=cpu,sky Review URL: https://codereview.chromium.org/14282002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@195224 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'win8/metro_driver')
-rw-r--r--win8/metro_driver/chrome_app_view_ash.cc59
-rw-r--r--win8/metro_driver/chrome_app_view_ash.h14
-rw-r--r--win8/metro_driver/file_picker_ash.cc71
-rw-r--r--win8/metro_driver/file_picker_ash.h18
4 files changed, 147 insertions, 15 deletions
diff --git a/win8/metro_driver/chrome_app_view_ash.cc b/win8/metro_driver/chrome_app_view_ash.cc
index 6d536fa..b21a572 100644
--- a/win8/metro_driver/chrome_app_view_ash.cc
+++ b/win8/metro_driver/chrome_app_view_ash.cc
@@ -81,6 +81,8 @@ class ChromeChannelListener : public IPC::Listener {
OnDisplayFileOpenDialog)
IPC_MESSAGE_HANDLER(MetroViewerHostMsg_DisplayFileSaveAs,
OnDisplayFileSaveAsDialog)
+ IPC_MESSAGE_HANDLER(MetroViewerHostMsg_DisplaySelectFolder,
+ OnDisplayFolderPicker)
IPC_MESSAGE_UNHANDLED(__debugbreak())
IPC_END_MESSAGE_MAP()
return true;
@@ -101,7 +103,7 @@ class ChromeChannelListener : public IPC::Listener {
void OnDisplayFileOpenDialog(const string16& title,
const string16& filter,
- const string16& default_path,
+ const base::FilePath& default_path,
bool allow_multiple_files) {
ui_proxy_->PostTask(FROM_HERE,
base::Bind(&ChromeAppViewAsh::OnDisplayFileOpenDialog,
@@ -121,6 +123,14 @@ class ChromeChannelListener : public IPC::Listener {
params));
}
+ void OnDisplayFolderPicker(const string16& title) {
+ ui_proxy_->PostTask(
+ FROM_HERE,
+ base::Bind(&ChromeAppViewAsh::OnDisplayFolderPicker,
+ base::Unretained(app_view_),
+ title));
+ }
+
scoped_refptr<base::MessageLoopProxy> ui_proxy_;
ChromeAppViewAsh* app_view_;
};
@@ -468,22 +478,23 @@ void ChromeAppViewAsh::OnSetCursor(HCURSOR cursor) {
::SetCursor(HCURSOR(cursor));
}
-void ChromeAppViewAsh::OnDisplayFileOpenDialog(const string16& title,
- const string16& filter,
- const string16& default_path,
- bool allow_multiple_files) {
+void ChromeAppViewAsh::OnDisplayFileOpenDialog(
+ const string16& title,
+ const string16& filter,
+ const base::FilePath& default_path,
+ bool allow_multiple_files) {
DVLOG(1) << __FUNCTION__;
// The OpenFilePickerSession instance is deleted when we receive a
// callback from the OpenFilePickerSession class about the completion of the
// operation.
- OpenFilePickerSession* open_file_picker =
+ FilePickerSessionBase* file_picker_ =
new OpenFilePickerSession(this,
title,
filter,
- default_path,
+ default_path.value(),
allow_multiple_files);
- open_file_picker->Run();
+ file_picker_->Run();
}
void ChromeAppViewAsh::OnDisplayFileSaveAsDialog(
@@ -491,11 +502,20 @@ void ChromeAppViewAsh::OnDisplayFileSaveAsDialog(
DVLOG(1) << __FUNCTION__;
// The SaveFilePickerSession instance is deleted when we receive a
- // callback from the OpenFilePickerSession class about the completion of the
+ // callback from the SaveFilePickerSession class about the completion of the
// operation.
- SaveFilePickerSession* save_file_picker =
+ FilePickerSessionBase* file_picker_ =
new SaveFilePickerSession(this, params);
- save_file_picker->Run();
+ file_picker_->Run();
+}
+
+void ChromeAppViewAsh::OnDisplayFolderPicker(const string16& title) {
+ DVLOG(1) << __FUNCTION__;
+ // The FolderPickerSession instance is deleted when we receive a
+ // callback from the FolderPickerSession class about the completion of the
+ // operation.
+ FilePickerSessionBase* file_picker_ = new FolderPickerSession(this, title);
+ file_picker_->Run();
}
void ChromeAppViewAsh::OnOpenFileCompleted(
@@ -509,7 +529,7 @@ void ChromeAppViewAsh::OnOpenFileCompleted(
success, open_file_picker->filenames()));
} else {
ui_channel_->Send(new MetroViewerHostMsg_FileOpenDone(
- success, open_file_picker->result()));
+ success, base::FilePath(open_file_picker->result())));
}
}
delete open_file_picker;
@@ -523,12 +543,25 @@ void ChromeAppViewAsh::OnSaveFileCompleted(
if (ui_channel_) {
ui_channel_->Send(new MetroViewerHostMsg_FileSaveAsDone(
success,
- save_file_picker->result(),
+ base::FilePath(save_file_picker->result()),
save_file_picker->filter_index()));
}
delete save_file_picker;
}
+void ChromeAppViewAsh::OnFolderPickerCompleted(
+ FolderPickerSession* folder_picker,
+ bool success) {
+ DVLOG(1) << __FUNCTION__;
+ DVLOG(1) << "Success: " << success;
+ if (ui_channel_) {
+ ui_channel_->Send(new MetroViewerHostMsg_SelectFolderDone(
+ success,
+ base::FilePath(folder_picker->result())));
+ }
+ delete folder_picker;
+}
+
HRESULT ChromeAppViewAsh::OnActivate(
winapp::Core::ICoreApplicationView*,
winapp::Activation::IActivatedEventArgs* args) {
diff --git a/win8/metro_driver/chrome_app_view_ash.h b/win8/metro_driver/chrome_app_view_ash.h
index 6952d3d..e649f8d 100644
--- a/win8/metro_driver/chrome_app_view_ash.h
+++ b/win8/metro_driver/chrome_app_view_ash.h
@@ -10,6 +10,7 @@
#include <windows.ui.input.h>
#include <windows.ui.viewmanagement.h>
+#include "base/files/file_path.h"
#include "base/memory/scoped_ptr.h"
#include "base/string16.h"
#include "ui/base/events/event_constants.h"
@@ -22,6 +23,8 @@ namespace IPC {
class OpenFilePickerSession;
class SaveFilePickerSession;
+class FolderPickerSession;
+class FilePickerSessionBase;
struct MetroViewerHostMsg_SaveAsDialogParams;
@@ -45,10 +48,11 @@ class ChromeAppViewAsh
void OnSetCursor(HCURSOR cursor);
void OnDisplayFileOpenDialog(const string16& title,
const string16& filter,
- const string16& default_path,
+ const base::FilePath& default_path,
bool allow_multiple_files);
void OnDisplayFileSaveAsDialog(
const MetroViewerHostMsg_SaveAsDialogParams& params);
+ void OnDisplayFolderPicker(const string16& title);
// This function is invoked when the open file operation completes. The
// result of the operation is passed in along with the OpenFilePickerSession
@@ -64,6 +68,13 @@ class ChromeAppViewAsh
void OnSaveFileCompleted(SaveFilePickerSession* save_file_picker,
bool success);
+ // This function is invoked when the folder picker operation completes. The
+ // result of the operation is passed in along with the FolderPickerSession
+ // instance which is deleted after we read the required information from
+ // the FolderPickerSession class.
+ void OnFolderPickerCompleted(FolderPickerSession* folder_picker,
+ bool success);
+
private:
HRESULT OnActivate(winapp::Core::ICoreApplicationView* view,
winapp::Activation::IActivatedEventArgs* args);
@@ -109,6 +120,7 @@ class ChromeAppViewAsh
EventRegistrationToken visibility_changed_token_;
EventRegistrationToken accel_keydown_token_;
EventRegistrationToken accel_keyup_token_;
+ EventRegistrationToken window_activated_token_;
// Keep state about which button is currently down, if any, as PointerMoved
// events do not contain that state, but Ash's MouseEvents need it.
diff --git a/win8/metro_driver/file_picker_ash.cc b/win8/metro_driver/file_picker_ash.cc
index 37f588a..5fb6a5a 100644
--- a/win8/metro_driver/file_picker_ash.cc
+++ b/win8/metro_driver/file_picker_ash.cc
@@ -377,7 +377,7 @@ SaveFilePickerSession::SaveFilePickerSession(
: FilePickerSessionBase(app_view,
params.title,
params.filter,
- params.suggested_name),
+ params.suggested_name.value()),
filter_index_(params.filter_index) {
}
@@ -544,3 +544,72 @@ HRESULT SaveFilePickerSession::FilePickerDone(SaveFileAsyncOp* async,
return S_OK;
}
+FolderPickerSession::FolderPickerSession(ChromeAppViewAsh* app_view,
+ const string16& title)
+ : FilePickerSessionBase(app_view, title, L"", L"") {}
+
+HRESULT FolderPickerSession::StartFilePicker() {
+ mswrw::HStringReference class_name(
+ RuntimeClass_Windows_Storage_Pickers_FolderPicker);
+
+ // Create the folder picker.
+ mswr::ComPtr<winstorage::Pickers::IFolderPicker> picker;
+ HRESULT hr = ::Windows::Foundation::ActivateInstance(
+ class_name.Get(), picker.GetAddressOf());
+ CheckHR(hr);
+
+ // Set the file type filter
+ mswr::ComPtr<winfoundtn::Collections::IVector<HSTRING>> filter;
+ hr = picker->get_FileTypeFilter(filter.GetAddressOf());
+ if (FAILED(hr))
+ return hr;
+
+ hr = filter->Append(mswrw::HStringReference(L"*").Get());
+ if (FAILED(hr))
+ return hr;
+
+ mswr::ComPtr<FolderPickerAsyncOp> completion;
+ hr = picker->PickSingleFolderAsync(&completion);
+ if (FAILED(hr))
+ return hr;
+
+ // Create the callback method.
+ typedef winfoundtn::IAsyncOperationCompletedHandler<
+ winstorage::StorageFolder*> HandlerDoneType;
+ mswr::ComPtr<HandlerDoneType> handler(mswr::Callback<HandlerDoneType>(
+ this, &FolderPickerSession::FolderPickerDone));
+ DCHECK(handler.Get() != NULL);
+ hr = completion->put_Completed(handler.Get());
+ return hr;
+}
+
+HRESULT FolderPickerSession::FolderPickerDone(FolderPickerAsyncOp* async,
+ AsyncStatus status) {
+ if (status == Completed) {
+ mswr::ComPtr<winstorage::IStorageFolder> folder;
+ HRESULT hr = async->GetResults(folder.GetAddressOf());
+
+ if (folder) {
+ mswr::ComPtr<winstorage::IStorageItem> storage_item;
+ if (SUCCEEDED(hr))
+ hr = folder.As(&storage_item);
+
+ mswrw::HString file_path;
+ if (SUCCEEDED(hr))
+ hr = storage_item->get_Path(file_path.GetAddressOf());
+
+ if (SUCCEEDED(hr)) {
+ string16 path_str = MakeStdWString(file_path.Get());
+ result_ = path_str;
+ success_ = true;
+ }
+ } else {
+ LOG(ERROR) << "NULL IStorageItem";
+ }
+ } else {
+ LOG(ERROR) << "Unexpected async status " << status;
+ }
+ app_view_->OnFolderPickerCompleted(this, success_);
+ return S_OK;
+}
+
diff --git a/win8/metro_driver/file_picker_ash.h b/win8/metro_driver/file_picker_ash.h
index 4426f5c..977e239 100644
--- a/win8/metro_driver/file_picker_ash.h
+++ b/win8/metro_driver/file_picker_ash.h
@@ -144,5 +144,23 @@ class SaveFilePickerSession : public FilePickerSessionBase {
DISALLOW_COPY_AND_ASSIGN(SaveFilePickerSession);
};
+// Provides functionality to display the folder picker.
+class FolderPickerSession : public FilePickerSessionBase {
+ public:
+ explicit FolderPickerSession(ChromeAppViewAsh* app_view,
+ const string16& title);
+
+ private:
+ virtual HRESULT StartFilePicker() OVERRIDE;
+
+ typedef winfoundtn::IAsyncOperation<winstorage::StorageFolder*>
+ FolderPickerAsyncOp;
+
+ // Called asynchronously when the folder picker is done.
+ HRESULT FolderPickerDone(FolderPickerAsyncOp* async, AsyncStatus status);
+
+ DISALLOW_COPY_AND_ASSIGN(FolderPickerSession);
+};
+
#endif // CHROME_BROWSER_UI_METRO_DRIVER_FILE_PICKER_ASH_H_