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