Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6252)

Unified Diff: chrome/browser/renderer_host/pepper/pepper_talk_host.cc

Issue 11359147: Convert the Pepper Talk API to use the new resource system. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/renderer_host/pepper/pepper_talk_host.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/renderer_host/pepper/pepper_talk_host.cc
diff --git a/chrome/browser/renderer_host/pepper/pepper_talk_host.cc b/chrome/browser/renderer_host/pepper/pepper_talk_host.cc
new file mode 100644
index 0000000000000000000000000000000000000000..b0b51ee4902ca426fd516bb8cba48291e8ff6e7a
--- /dev/null
+++ b/chrome/browser/renderer_host/pepper/pepper_talk_host.cc
@@ -0,0 +1,102 @@
+// 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/renderer_host/pepper/pepper_talk_host.h"
+
+#include "base/bind.h"
+#include "content/public/browser/browser_ppapi_host.h"
+#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/render_view_host.h"
+#include "grit/generated_resources.h"
+#include "ppapi/c/pp_errors.h"
+#include "ppapi/host/host_message_context.h"
+#include "ppapi/host/ppapi_host.h"
+#include "ppapi/proxy/ppapi_messages.h"
+#include "ui/base/l10n/l10n_util.h"
+
+#if defined(USE_ASH)
+#include "ash/shell.h"
+#include "ash/shell_window_ids.h"
+#include "chrome/browser/ui/simple_message_box.h"
+#include "ui/aura/window.h"
+#endif
+
+namespace chrome {
+
+namespace {
+
+ppapi::host::ReplyMessageContext GetPermissionOnUIThread(
+ int render_process_id,
+ int render_view_id,
+ ppapi::host::ReplyMessageContext reply) {
+ DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
+ reply.params.set_result(0);
+
+ content::RenderViewHost* render_view_host =
+ content::RenderViewHost::FromID(render_process_id, render_view_id);
+ if (!render_view_host)
+ return reply; // RVH destroyed while task was pending.
+
+#if defined(USE_ASH)
+ // TODO(brettw). We should not be grabbing the active toplevel window, we
+ // should use the toplevel window associated with the render view.
+ const string16 title = l10n_util::GetStringUTF16(
+ IDS_GTALK_SCREEN_SHARE_DIALOG_TITLE);
+ const string16 message = l10n_util::GetStringUTF16(
+ IDS_GTALK_SCREEN_SHARE_DIALOG_MESSAGE);
+
+ aura::Window* parent = ash::Shell::GetContainer(
+ ash::Shell::GetActiveRootWindow(),
+ ash::internal::kShellWindowId_SystemModalContainer);
+ reply.params.set_result(static_cast<int32_t>(
+ chrome::ShowMessageBox(parent, title, message,
+ chrome::MESSAGE_BOX_TYPE_QUESTION) ==
+ chrome::MESSAGE_BOX_RESULT_YES));
+#else
+ NOTIMPLEMENTED();
+#endif
+ return reply;
+}
+
+} // namespace
+
+PepperTalkHost::PepperTalkHost(content::BrowserPpapiHost* host,
+ PP_Instance instance,
+ PP_Resource resource)
+ : ppapi::host::ResourceHost(host->GetPpapiHost(), instance, resource),
+ weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
+ browser_ppapi_host_(host) {
+}
+
+PepperTalkHost::~PepperTalkHost() {
+}
+
+int32_t PepperTalkHost::OnResourceMessageReceived(
+ const IPC::Message& msg,
+ ppapi::host::HostMessageContext* context) {
+ // We only have one message with no parameters.
+ if (msg.type() != PpapiHostMsg_Talk_GetPermission::ID)
+ return 0;
+
+ int render_process_id = 0;
+ int render_view_id = 0;
+ browser_ppapi_host_->GetRenderViewIDsForInstance(
+ pp_instance(), &render_process_id, &render_view_id);
+
+ content::BrowserThread::PostTaskAndReplyWithResult(
+ content::BrowserThread::UI, FROM_HERE,
+ base::Bind(&GetPermissionOnUIThread, render_process_id, render_view_id,
+ context->MakeReplyMessageContext()),
+ base::Bind(&PepperTalkHost::GotTalkPermission,
+ weak_factory_.GetWeakPtr()));
+ return PP_OK_COMPLETIONPENDING;
+}
+
+void PepperTalkHost::GotTalkPermission(
+ ppapi::host::ReplyMessageContext reply) {
+ DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
+ host()->SendReply(reply, PpapiPluginMsg_Talk_GetPermissionReply());
+}
+
+} // namespace chrome
« no previous file with comments | « chrome/browser/renderer_host/pepper/pepper_talk_host.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698