Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / content / plugin / plugin_channel.h
blob94ae6398cc761eb62bb0d5a2c8fafd687301c1df
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CONTENT_PLUGIN_PLUGIN_CHANNEL_H_
6 #define CONTENT_PLUGIN_PLUGIN_CHANNEL_H_
8 #include <vector>
9 #include "base/memory/ref_counted.h"
10 #include "base/process/process.h"
11 #include "build/build_config.h"
12 #include "content/child/npapi/np_channel_base.h"
13 #include "content/child/scoped_child_process_reference.h"
14 #include "content/plugin/webplugin_delegate_stub.h"
16 namespace base {
17 class WaitableEvent;
20 namespace content {
22 // Encapsulates an IPC channel between the plugin process and one renderer
23 // process. On the renderer side there's a corresponding PluginChannelHost.
24 class PluginChannel : public NPChannelBase {
25 public:
26 // Get a new PluginChannel object for the current process to talk to the
27 // given renderer process. The renderer ID is an opaque unique ID generated
28 // by the browser.
29 static PluginChannel* GetPluginChannel(
30 int renderer_id,
31 base::SingleThreadTaskRunner* ipc_task_runner,
32 IPC::AttachmentBroker* broker);
34 // Send a message to all renderers that the process is going to shutdown.
35 static void NotifyRenderersOfPendingShutdown();
37 // IPC::Listener:
38 bool Send(IPC::Message* msg) override;
39 bool OnMessageReceived(const IPC::Message& message) override;
40 void OnChannelError() override;
42 int renderer_id() { return renderer_id_; }
44 int GenerateRouteID() override;
46 // Returns the event that's set when a call to the renderer causes a modal
47 // dialog to come up.
48 base::WaitableEvent* GetModalDialogEvent(int render_view_id) override;
50 bool in_send() { return in_send_ != 0; }
52 bool incognito() { return incognito_; }
53 void set_incognito(bool value) { incognito_ = value; }
55 #if defined(OS_POSIX)
56 base::ScopedFD TakeRendererFileDescriptor() {
57 return channel_->TakeClientFileDescriptor();
59 #endif
61 protected:
62 ~PluginChannel() override;
64 // NPChannelBase::
65 void CleanUp() override;
66 bool Init(base::SingleThreadTaskRunner* ipc_task_runner,
67 bool create_pipe_now,
68 base::WaitableEvent* shutdown_event,
69 IPC::AttachmentBroker* broker) override;
71 private:
72 class MessageFilter;
74 // Called on the plugin thread
75 PluginChannel();
77 bool OnControlMessageReceived(const IPC::Message& msg) override;
79 static NPChannelBase* ClassFactory() { return new PluginChannel(); }
81 void OnCreateInstance(const std::string& mime_type, int* instance_id);
82 void OnDestroyInstance(int instance_id, IPC::Message* reply_msg);
83 void OnGenerateRouteID(int* route_id);
84 void OnClearSiteData(const std::string& site,
85 uint64 flags,
86 uint64 max_age);
87 void OnDidAbortLoading(int render_view_id);
89 std::vector<scoped_refptr<WebPluginDelegateStub> > plugin_stubs_;
91 ScopedChildProcessReference process_ref_;
93 // The id of the renderer who is on the other side of the channel.
94 int renderer_id_;
96 int in_send_; // Tracks if we're in a Send call.
97 bool log_messages_; // True if we should log sent and received messages.
98 bool incognito_; // True if the renderer is in incognito mode.
99 scoped_refptr<MessageFilter> filter_; // Handles the modal dialog events.
101 // Dummy NPP value used in the plugin process to represent entities other
102 // that other plugin instances for the purpose of object ownership tracking.
103 scoped_ptr<struct _NPP> npp_;
105 DISALLOW_COPY_AND_ASSIGN(PluginChannel);
108 } // namespace content
110 #endif // CONTENT_PLUGIN_PLUGIN_CHANNEL_H_