summaryrefslogtreecommitdiffstats
path: root/ppapi
diff options
context:
space:
mode:
authorbbudge@chromium.org <bbudge@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-13 02:48:50 +0000
committerbbudge@chromium.org <bbudge@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-13 02:48:50 +0000
commit459fba846839922dc77873aa3181a2684cd03e0c (patch)
treed48784892c57993f21e92b6fdebf99836845d5e7 /ppapi
parent721c0ceae9fef3230bd36b0d1b742f231f37ad19 (diff)
downloadchromium_src-459fba846839922dc77873aa3181a2684cd03e0c.zip
chromium_src-459fba846839922dc77873aa3181a2684cd03e0c.tar.gz
chromium_src-459fba846839922dc77873aa3181a2684cd03e0c.tar.bz2
Implement 'SAVEAS' mode for PPB_FileChooser_Impl. Also, fix the Save File dialog when thesuggested file name is a root directory, such as "C:\".
BUG=73070 TEST=manual Review URL: http://codereview.chromium.org/8142018 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@105247 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi')
-rw-r--r--ppapi/proxy/ppapi_messages.h9
-rw-r--r--ppapi/proxy/ppb_file_chooser_proxy.cc59
-rw-r--r--ppapi/proxy/ppb_file_chooser_proxy.h10
-rw-r--r--ppapi/proxy/resource_creation_proxy.cc2
-rw-r--r--ppapi/proxy/resource_creation_proxy.h2
-rw-r--r--ppapi/thunk/ppb_file_chooser_api.h6
-rw-r--r--ppapi/thunk/ppb_file_chooser_thunk.cc31
-rw-r--r--ppapi/thunk/resource_creation_api.h2
-rw-r--r--ppapi/thunk/thunk.h3
9 files changed, 104 insertions, 20 deletions
diff --git a/ppapi/proxy/ppapi_messages.h b/ppapi/proxy/ppapi_messages.h
index a650577..3b61d1a 100644
--- a/ppapi/proxy/ppapi_messages.h
+++ b/ppapi/proxy/ppapi_messages.h
@@ -570,10 +570,13 @@ IPC_SYNC_MESSAGE_ROUTED1_1(PpapiHostMsg_PPBCursorControl_CanLockCursor,
IPC_SYNC_MESSAGE_ROUTED3_1(PpapiHostMsg_PPBFileChooser_Create,
PP_Instance /* instance */,
int /* mode */,
- ppapi::proxy::SerializedVar /* accept_mime_types */,
+ std::string /* accept_mime_types */,
ppapi::HostResource /* result */)
-IPC_MESSAGE_ROUTED1(PpapiHostMsg_PPBFileChooser_Show,
- ppapi::HostResource /* file_chooser */)
+IPC_MESSAGE_ROUTED4(PpapiHostMsg_PPBFileChooser_Show,
+ ppapi::HostResource /* file_chooser */,
+ bool /* save_as */,
+ std::string /* suggested_file_name */,
+ bool /* require_user_gesture */)
// PPB_FileRef.
diff --git a/ppapi/proxy/ppb_file_chooser_proxy.cc b/ppapi/proxy/ppb_file_chooser_proxy.cc
index d6850a5..d128439 100644
--- a/ppapi/proxy/ppb_file_chooser_proxy.cc
+++ b/ppapi/proxy/ppb_file_chooser_proxy.cc
@@ -37,6 +37,10 @@ class FileChooser : public Resource,
// PPB_FileChooser_API implementation.
virtual int32_t Show(const PP_CompletionCallback& callback) OVERRIDE;
virtual PP_Resource GetNextChosenFile() OVERRIDE;
+ virtual int32_t ShowWithoutUserGesture(
+ bool save_as,
+ const char* suggested_file_name,
+ const PP_CompletionCallback& callback) OVERRIDE;
// Handles the choose complete notification from the host.
void ChooseComplete(
@@ -44,6 +48,11 @@ class FileChooser : public Resource,
const std::vector<PPB_FileRef_CreateInfo>& chosen_files);
private:
+ int32_t Show(bool require_user_gesture,
+ bool save_as,
+ const char* suggested_file_name,
+ const PP_CompletionCallback& callback);
+
PP_CompletionCallback current_show_callback_;
// All files returned by the current show callback that haven't yet been
@@ -84,6 +93,20 @@ PPB_FileChooser_API* FileChooser::AsPPB_FileChooser_API() {
}
int32_t FileChooser::Show(const PP_CompletionCallback& callback) {
+ return Show(true, false, NULL, callback);
+}
+
+int32_t FileChooser::ShowWithoutUserGesture(
+ bool save_as,
+ const char* suggested_file_name,
+ const PP_CompletionCallback& callback) {
+ return Show(false, save_as, suggested_file_name, callback);
+}
+
+int32_t FileChooser::Show(bool require_user_gesture,
+ bool save_as,
+ const char* suggested_file_name,
+ const PP_CompletionCallback& callback) {
if (!callback.func)
return PP_ERROR_BLOCKS_MAIN_THREAD;
@@ -93,7 +116,11 @@ int32_t FileChooser::Show(const PP_CompletionCallback& callback) {
current_show_callback_ = callback;
PluginDispatcher::GetForResource(this)->Send(
new PpapiHostMsg_PPBFileChooser_Show(
- INTERFACE_ID_PPB_FILE_CHOOSER, host_resource()));
+ INTERFACE_ID_PPB_FILE_CHOOSER,
+ host_resource(),
+ save_as,
+ suggested_file_name,
+ require_user_gesture));
return PP_OK_COMPLETIONPENDING;
}
@@ -135,7 +162,7 @@ PPB_FileChooser_Proxy::~PPB_FileChooser_Proxy() {
PP_Resource PPB_FileChooser_Proxy::CreateProxyResource(
PP_Instance instance,
PP_FileChooserMode_Dev mode,
- const PP_Var& accept_mime_types) {
+ const char* accept_mime_types) {
Dispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
if (!dispatcher)
return 0;
@@ -143,7 +170,8 @@ PP_Resource PPB_FileChooser_Proxy::CreateProxyResource(
HostResource result;
dispatcher->Send(new PpapiHostMsg_PPBFileChooser_Create(
INTERFACE_ID_PPB_FILE_CHOOSER, instance,
- mode, SerializedVarSendInput(dispatcher, accept_mime_types),
+ mode,
+ accept_mime_types,
&result));
if (result.is_null())
@@ -169,22 +197,35 @@ bool PPB_FileChooser_Proxy::OnMessageReceived(const IPC::Message& msg) {
void PPB_FileChooser_Proxy::OnMsgCreate(
PP_Instance instance,
int mode,
- SerializedVarReceiveInput accept_mime_types,
+ std::string accept_mime_types,
HostResource* result) {
thunk::EnterResourceCreation enter(instance);
if (enter.succeeded()) {
result->SetHostResource(instance, enter.functions()->CreateFileChooser(
- instance, static_cast<PP_FileChooserMode_Dev>(mode),
- accept_mime_types.Get(dispatcher())));
+ instance,
+ static_cast<PP_FileChooserMode_Dev>(mode),
+ accept_mime_types.c_str()));
}
}
-void PPB_FileChooser_Proxy::OnMsgShow(const HostResource& chooser) {
+void PPB_FileChooser_Proxy::OnMsgShow(
+ const HostResource& chooser,
+ bool save_as,
+ std::string suggested_file_name,
+ bool require_user_gesture) {
EnterHostFromHostResourceForceCallback<PPB_FileChooser_API> enter(
chooser, callback_factory_, &PPB_FileChooser_Proxy::OnShowCallback,
chooser);
- if (enter.succeeded())
- enter.SetResult(enter.object()->Show(enter.callback()));
+ if (enter.succeeded()) {
+ if (require_user_gesture) {
+ enter.SetResult(enter.object()->Show(enter.callback()));
+ } else {
+ enter.SetResult(enter.object()->ShowWithoutUserGesture(
+ save_as,
+ suggested_file_name.c_str(),
+ enter.callback()));
+ }
+ }
}
void PPB_FileChooser_Proxy::OnMsgChooseComplete(
diff --git a/ppapi/proxy/ppb_file_chooser_proxy.h b/ppapi/proxy/ppb_file_chooser_proxy.h
index f1dcd95..c7e2f48 100644
--- a/ppapi/proxy/ppb_file_chooser_proxy.h
+++ b/ppapi/proxy/ppb_file_chooser_proxy.h
@@ -20,6 +20,7 @@ struct PPB_FileChooser_Dev;
namespace ppapi {
class HostResource;
+struct PPB_FileChooserTrusted;
struct PPB_FileRef_CreateInfo;
namespace proxy {
@@ -34,7 +35,7 @@ class PPB_FileChooser_Proxy : public InterfaceProxy {
static PP_Resource CreateProxyResource(
PP_Instance instance,
PP_FileChooserMode_Dev mode,
- const PP_Var& accept_mime_types);
+ const char* accept_mime_types);
// InterfaceProxy implementation.
virtual bool OnMessageReceived(const IPC::Message& msg);
@@ -45,9 +46,12 @@ class PPB_FileChooser_Proxy : public InterfaceProxy {
// Plugin -> host message handlers.
void OnMsgCreate(PP_Instance instance,
int mode,
- SerializedVarReceiveInput accept_mime_types,
+ std::string accept_mime_types,
ppapi::HostResource* result);
- void OnMsgShow(const ppapi::HostResource& chooser);
+ void OnMsgShow(const ppapi::HostResource& chooser,
+ bool save_as,
+ std::string suggested_file_name,
+ bool require_user_gesture);
// Host -> plugin message handlers.
void OnMsgChooseComplete(
diff --git a/ppapi/proxy/resource_creation_proxy.cc b/ppapi/proxy/resource_creation_proxy.cc
index a0b4b6a..b7d6c0c 100644
--- a/ppapi/proxy/resource_creation_proxy.cc
+++ b/ppapi/proxy/resource_creation_proxy.cc
@@ -120,7 +120,7 @@ PP_Resource ResourceCreationProxy::CreateDirectoryReader(
PP_Resource ResourceCreationProxy::CreateFileChooser(
PP_Instance instance,
PP_FileChooserMode_Dev mode,
- const PP_Var& accept_mime_types) {
+ const char* accept_mime_types) {
return PPB_FileChooser_Proxy::CreateProxyResource(instance, mode,
accept_mime_types);
}
diff --git a/ppapi/proxy/resource_creation_proxy.h b/ppapi/proxy/resource_creation_proxy.h
index 1fdac1c..74812f4 100644
--- a/ppapi/proxy/resource_creation_proxy.h
+++ b/ppapi/proxy/resource_creation_proxy.h
@@ -61,7 +61,7 @@ class ResourceCreationProxy : public InterfaceProxy,
virtual PP_Resource CreateFileChooser(
PP_Instance instance,
PP_FileChooserMode_Dev mode,
- const PP_Var& accept_mime_types) OVERRIDE;
+ const char* accept_mime_types) OVERRIDE;
virtual PP_Resource CreateFileIO(PP_Instance instance) OVERRIDE;
virtual PP_Resource CreateFileRef(PP_Resource file_system,
const char* path) OVERRIDE;
diff --git a/ppapi/thunk/ppb_file_chooser_api.h b/ppapi/thunk/ppb_file_chooser_api.h
index fba94c7..494f7bd 100644
--- a/ppapi/thunk/ppb_file_chooser_api.h
+++ b/ppapi/thunk/ppb_file_chooser_api.h
@@ -16,6 +16,12 @@ class PPB_FileChooser_API {
virtual int32_t Show(const PP_CompletionCallback& callback) = 0;
virtual PP_Resource GetNextChosenFile() = 0;
+
+ // Trusted API.
+ virtual int32_t ShowWithoutUserGesture(
+ bool save_as,
+ const char* suggested_file_name,
+ const PP_CompletionCallback& callback) = 0;
};
} // namespace thunk
diff --git a/ppapi/thunk/ppb_file_chooser_thunk.cc b/ppapi/thunk/ppb_file_chooser_thunk.cc
index 774ef03..e5cbc5d 100644
--- a/ppapi/thunk/ppb_file_chooser_thunk.cc
+++ b/ppapi/thunk/ppb_file_chooser_thunk.cc
@@ -5,6 +5,8 @@
#include "ppapi/c/dev/ppb_file_chooser_dev.h"
#include "ppapi/c/pp_completion_callback.h"
#include "ppapi/c/pp_errors.h"
+#include "ppapi/c/trusted/ppb_file_chooser_trusted.h"
+#include "ppapi/shared_impl/var.h"
#include "ppapi/thunk/common.h"
#include "ppapi/thunk/enter.h"
#include "ppapi/thunk/thunk.h"
@@ -22,8 +24,10 @@ PP_Resource Create(PP_Instance instance,
EnterFunction<ResourceCreationAPI> enter(instance, true);
if (enter.failed())
return 0;
- return enter.functions()->CreateFileChooser(instance, mode,
- accept_mime_types);
+ scoped_refptr<StringVar> string_var =
+ StringVar::FromPPVar(accept_mime_types);
+ std::string str = string_var ? string_var->value() : std::string();
+ return enter.functions()->CreateFileChooser(instance, mode, str.c_str());
}
PP_Bool IsFileChooser(PP_Resource resource) {
@@ -46,6 +50,21 @@ PP_Resource GetNextChosenFile(PP_Resource chooser) {
return enter.object()->GetNextChosenFile();
}
+int32_t ShowWithoutUserGesture(PP_Resource chooser,
+ PP_Bool save_as,
+ PP_Var suggested_file_name,
+ PP_CompletionCallback callback) {
+ EnterResource<PPB_FileChooser_API> enter(chooser, true);
+ if (enter.failed())
+ return MayForceCallback(callback, PP_ERROR_BADRESOURCE);
+ scoped_refptr<StringVar> string_var =
+ StringVar::FromPPVar(suggested_file_name);
+ std::string str = string_var ? string_var->value() : std::string();
+ int32_t result = enter.object()->ShowWithoutUserGesture(
+ save_as == PP_TRUE, str.c_str(), callback);
+ return MayForceCallback(callback, result);
+}
+
const PPB_FileChooser_Dev g_ppb_file_chooser_thunk = {
&Create,
&IsFileChooser,
@@ -53,11 +72,19 @@ const PPB_FileChooser_Dev g_ppb_file_chooser_thunk = {
&GetNextChosenFile
};
+const PPB_FileChooserTrusted g_ppb_file_chooser_trusted_thunk = {
+ &ShowWithoutUserGesture
+};
+
} // namespace
const PPB_FileChooser_Dev* GetPPB_FileChooser_Dev_Thunk() {
return &g_ppb_file_chooser_thunk;
}
+const PPB_FileChooserTrusted* GetPPB_FileChooser_Trusted_Thunk() {
+ return &g_ppb_file_chooser_trusted_thunk;
+}
+
} // namespace thunk
} // namespace ppapi
diff --git a/ppapi/thunk/resource_creation_api.h b/ppapi/thunk/resource_creation_api.h
index 256c9e8..59cc1c2 100644
--- a/ppapi/thunk/resource_creation_api.h
+++ b/ppapi/thunk/resource_creation_api.h
@@ -62,7 +62,7 @@ class ResourceCreationAPI {
virtual PP_Resource CreateFileChooser(
PP_Instance instance,
PP_FileChooserMode_Dev mode,
- const PP_Var& accept_mime_types) = 0;
+ const char* accept_mime_types) = 0;
virtual PP_Resource CreateFileIO(PP_Instance instance) = 0;
virtual PP_Resource CreateFileRef(PP_Resource file_system,
const char* path) = 0;
diff --git a/ppapi/thunk/thunk.h b/ppapi/thunk/thunk.h
index fe90eff..bac3a63 100644
--- a/ppapi/thunk/thunk.h
+++ b/ppapi/thunk/thunk.h
@@ -31,6 +31,7 @@ struct PPB_AudioTrusted;
struct PPB_BrokerTrusted;
struct PPB_BufferTrusted;
struct PPB_Context3DTrusted_Dev;
+struct PPB_FileChooserTrusted;
struct PPB_FileIOTrusted;
struct PPB_Flash_Menu;
struct PPB_Flash_NetConnector;
@@ -56,6 +57,8 @@ PPAPI_THUNK_EXPORT const PPB_BrokerTrusted* GetPPB_Broker_Thunk();
PPAPI_THUNK_EXPORT const PPB_BufferTrusted* GetPPB_BufferTrusted_Thunk();
PPAPI_THUNK_EXPORT const PPB_Context3DTrusted_Dev*
GetPPB_Context3DTrusted_Thunk();
+PPAPI_THUNK_EXPORT const PPB_FileChooserTrusted*
+ GetPPB_FileChooser_Trusted_Thunk();
PPAPI_THUNK_EXPORT const PPB_FileIOTrusted* GetPPB_FileIOTrusted_Thunk();
PPAPI_THUNK_EXPORT const PPB_Flash_Menu* GetPPB_Flash_Menu_Thunk();
PPAPI_THUNK_EXPORT const PPB_Flash_NetConnector*