blob: 57a689ba8bd1ea5b460099482049d311afe40091 [file] [log] [blame]
[email protected]d0b8e5f2010-05-18 04:26:021// Copyright (c) 2010 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.
[email protected]44f9c952011-01-02 06:05:394
[email protected]d0b8e5f2010-05-18 04:26:025#ifndef CHROME_FRAME_CUSTOM_SYNC_CALL_CONTEXT_H_
6#define CHROME_FRAME_CUSTOM_SYNC_CALL_CONTEXT_H_
7
8#include <vector>
9#include "base/ref_counted.h"
[email protected]44f9c952011-01-02 06:05:3910#include "base/synchronization/waitable_event.h"
[email protected]d0b8e5f2010-05-18 04:26:0211#include "chrome_frame/sync_msg_reply_dispatcher.h"
12#include "chrome_frame/chrome_frame_automation.h"
13#include "ipc/ipc_sync_message.h"
14
15// TODO(ananta)
16// Move the implementations of these classes to the source file.
17
18// Class that maintains context during the async load/install extension
19// operation. When done, InstallExtensionComplete is posted back to the UI
20// thread so that the users of ChromeFrameAutomationClient can be notified.
21class InstallExtensionContext
22 : public SyncMessageReplyDispatcher::SyncMessageCallContext {
23 public:
24 typedef Tuple1<AutomationMsg_ExtensionResponseValues> output_type;
25
26 InstallExtensionContext(ChromeFrameAutomationClient* client,
27 const FilePath& crx_path, void* user_data) : client_(client),
28 crx_path_(crx_path), user_data_(user_data) {
29 }
30
31 ~InstallExtensionContext() {
32 }
33
34 void Completed(AutomationMsg_ExtensionResponseValues res) {
35 client_->PostTask(FROM_HERE, NewRunnableMethod(client_.get(),
36 &ChromeFrameAutomationClient::InstallExtensionComplete, crx_path_,
37 user_data_, res));
38 }
39
40 private:
41 scoped_refptr<ChromeFrameAutomationClient> client_;
42 FilePath crx_path_;
43 void* user_data_;
44};
45
46// Class that maintains context during the async retrieval of fetching the
47// list of enabled extensions. When done, GetEnabledExtensionsComplete is
48// posted back to the UI thread so that the users of
49// ChromeFrameAutomationClient can be notified.
50class GetEnabledExtensionsContext
51 : public SyncMessageReplyDispatcher::SyncMessageCallContext {
52 public:
53 typedef Tuple1<std::vector<FilePath> > output_type;
54
55 GetEnabledExtensionsContext(
56 ChromeFrameAutomationClient* client, void* user_data) : client_(client),
57 user_data_(user_data) {
58 extension_directories_ = new std::vector<FilePath>();
59 }
60
61 ~GetEnabledExtensionsContext() {
62 // ChromeFrameAutomationClient::GetEnabledExtensionsComplete takes
63 // ownership of extension_directories_.
64 }
65
66 std::vector<FilePath>* extension_directories() {
67 return extension_directories_;
68 }
69
70 void Completed(
71 std::vector<FilePath> result) {
72 (*extension_directories_) = result;
73 client_->PostTask(FROM_HERE, NewRunnableMethod(client_.get(),
74 &ChromeFrameAutomationClient::GetEnabledExtensionsComplete,
75 user_data_, extension_directories_));
76 }
77
78 private:
79 scoped_refptr<ChromeFrameAutomationClient> client_;
80 std::vector<FilePath>* extension_directories_;
81 void* user_data_;
82};
83
84// Class that maintains contextual information for the create and connect
85// external tab operations.
86class CreateExternalTabContext
87 : public SyncMessageReplyDispatcher::SyncMessageCallContext {
88 public:
[email protected]751bf4b2010-11-05 22:06:3189 typedef Tuple4<HWND, HWND, int, int> output_type;
[email protected]d0b8e5f2010-05-18 04:26:0290 explicit CreateExternalTabContext(ChromeFrameAutomationClient* client)
91 : client_(client) {
92 }
93
[email protected]751bf4b2010-11-05 22:06:3194 void Completed(HWND chrome_window, HWND tab_window, int tab_handle,
95 int session_id) {
[email protected]ef8561d2010-05-19 02:49:1896 AutomationLaunchResult launch_result =
97 client_->CreateExternalTabComplete(chrome_window, tab_window,
[email protected]751bf4b2010-11-05 22:06:3198 tab_handle, session_id);
[email protected]d0b8e5f2010-05-18 04:26:0299 client_->PostTask(FROM_HERE,
[email protected]a5205b62010-05-19 01:31:31100 NewRunnableMethod(
101 client_.get(),
102 &ChromeFrameAutomationClient::InitializeComplete,
[email protected]ef8561d2010-05-19 02:49:18103 launch_result));
[email protected]d0b8e5f2010-05-18 04:26:02104 }
105
106 private:
107 scoped_refptr<ChromeFrameAutomationClient> client_;
108};
109
110// This class maintains context information for the BeginNavigate operations
111// pertaining to the external tab.
112class BeginNavigateContext
113 : public SyncMessageReplyDispatcher::SyncMessageCallContext {
114 public:
115 explicit BeginNavigateContext(ChromeFrameAutomationClient* client)
116 : client_(client) {}
117
118 typedef Tuple1<AutomationMsg_NavigationResponseValues> output_type;
119
120 void Completed(AutomationMsg_NavigationResponseValues response) {
121 client_->BeginNavigateCompleted(response);
122 }
123
124 private:
125 scoped_refptr<ChromeFrameAutomationClient> client_;
126};
127
[email protected]d9d8f0c2010-09-17 21:47:16128// Class that maintains contextual information for the unload operation, i.e.
129// when the user attempts to navigate away from a page rendered in ChromeFrame.
130class UnloadContext
131 : public SyncMessageReplyDispatcher::SyncMessageCallContext {
132 public:
133 typedef Tuple1<bool> output_type;
134 explicit UnloadContext(base::WaitableEvent* unload_done, bool* should_unload)
135 : should_unload_(should_unload),
136 unload_done_(unload_done) {
137 }
138
139 void Completed(bool should_unload) {
140 *should_unload_ = should_unload;
141 unload_done_->Signal();
142 should_unload_ = NULL;
143 unload_done_ = NULL;
144 // This object will be destroyed after this. Cannot access any members
145 // on returning from this function.
146 }
147
148 private:
149 base::WaitableEvent* unload_done_;
150 bool* should_unload_;
151};
152
[email protected]d0b8e5f2010-05-18 04:26:02153#endif // CHROME_FRAME_CUSTOM_SYNC_CALL_CONTEXT_H_