Skip to content
This repository has been archived by the owner on Apr 3, 2020. It is now read-only.

Commit

Permalink
[Permission] support to pop up a permission dialog
Browse files Browse the repository at this point in the history
* If the request permission need user consent, it will pop up a
  dialog for user select
  • Loading branch information
xuzhang committed Apr 4, 2014
1 parent 0891889 commit 314e955
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
18 changes: 17 additions & 1 deletion application/browser/application_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
#include "base/message_loop/message_loop.h"
#include "base/path_service.h"
#include "base/version.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/storage_partition.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_observer.h"
#include "ui/views/widget/widget.h"
#include "xwalk/application/browser/application_event_manager.h"
#include "xwalk/application/browser/application.h"
#include "xwalk/application/browser/application_storage.h"
Expand All @@ -24,6 +26,7 @@
#include "xwalk/application/common/application_file_util.h"
#include "xwalk/application/common/event_names.h"
#include "xwalk/application/common/permission_policy_manager.h"
#include "xwalk/application/common/permission_dialog.h"
#include "xwalk/runtime/browser/runtime_context.h"
#include "xwalk/runtime/browser/runtime.h"
#include "xwalk/runtime/browser/xwalk_runner.h"
Expand All @@ -33,6 +36,7 @@
#include "xwalk/application/browser/installer/tizen/service_package_installer.h"
#endif

using content::BrowserThread;
namespace xwalk {
namespace application {

Expand Down Expand Up @@ -674,7 +678,9 @@ void ApplicationService::CheckAPIAccessControl(const std::string& app_id,
// TODO(Bai): We needed to pop-up a dialog asking user to chose one from
// either allow/deny for session/one shot/forever. Then, we need to update
// the session and persistent policy accordingly.
callback.Run(UNDEFINED_RUNTIME_PERM);
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
base::Bind(&ApplicationService::ShowPermissionDialog,
base::Unretained(this), app_id, permission_name, callback));
return;
}
if (perm == ALLOW) {
Expand Down Expand Up @@ -705,5 +711,15 @@ bool ApplicationService::RegisterPermissions(const std::string& app_id,
return app->RegisterPermissions(extension_name, perm_table);
}

void ApplicationService::ShowPermissionDialog(const std::string& app_id,
const std::string& permission,
const PermissionCallback& callback) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));

PermissionDialog* dialog_ = new PermissionDialog(app_id, permission);
dialog_->SetShowDialogCallback(callback);
views::Widget::CreateWindow(dialog_)->Show();
}

} // namespace application
} // namespace xwalk
4 changes: 4 additions & 0 deletions application/browser/application_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ class ApplicationService : public Application::Observer {
// Implementation of Application::Observer.
virtual void OnApplicationTerminated(Application* app) OVERRIDE;

// Show Permission dialog to end user
void ShowPermissionDialog(const std::string& app_id,
const std::string& permission,
const PermissionCallback& callback);

xwalk::RuntimeContext* runtime_context_;
ApplicationStorage* application_storage_;
Expand Down

0 comments on commit 314e955

Please sign in to comment.