OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 // | 4 // |
5 // Tab API implementation. | 5 // Tab API implementation. |
6 // | 6 // |
7 // Tab IDs are the window handle of the "TabWindowClass" window class | 7 // Tab IDs are the window handle of the "TabWindowClass" window class |
8 // of the whole tab. | 8 // of the whole tab. |
9 // | 9 // |
10 // To find the chrome.window.* "window ID" we can just get the top-level parent | 10 // To find the chrome.window.* "window ID" we can just get the top-level parent |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 input_list->GetInteger(1, &tab_id); | 119 input_list->GetInteger(1, &tab_id); |
120 DCHECK(tab_id == dispatcher->GetTabIdFromHandle( | 120 DCHECK(tab_id == dispatcher->GetTabIdFromHandle( |
121 reinterpret_cast<HWND>(tab_handle))); | 121 reinterpret_cast<HWND>(tab_handle))); |
122 #endif // DEBUG | 122 #endif // DEBUG |
123 | 123 |
124 HWND tab_window = reinterpret_cast<HWND>(tab_handle); | 124 HWND tab_window = reinterpret_cast<HWND>(tab_handle); |
125 dispatcher->DeleteTabHandle(tab_window); | 125 dispatcher->DeleteTabHandle(tab_window); |
126 return false; | 126 return false; |
127 } | 127 } |
128 | 128 |
| 129 bool GetIdAndHandleFromArgs(const std::string& input_args, int* id, |
| 130 HWND* handle) { |
| 131 DCHECK(id != NULL); |
| 132 DCHECK(handle != NULL); |
| 133 scoped_ptr<ListValue> input_list; |
| 134 *id = kInvalidChromeSessionId; |
| 135 if (!api_module_util::GetListAndIntegerValue(input_args, &input_list, id) || |
| 136 *id == kInvalidChromeSessionId) { |
| 137 NOTREACHED() << "An invalid argument was passed to GetIdAndHandleFromArgs"; |
| 138 return false; |
| 139 } |
| 140 |
| 141 int tab_handle = 0; |
| 142 if (!input_list->GetInteger(1, &tab_handle) || tab_handle == 0) { |
| 143 NOTREACHED() << "An invalid argument was passed to GetIdAndHandleFromArgs"; |
| 144 return false; |
| 145 } |
| 146 *handle = reinterpret_cast<HWND>(tab_handle); |
| 147 return true; |
| 148 } |
| 149 |
| 150 bool CeeeMapTabIdToHandle(const std::string& input_args, |
| 151 std::string* converted_args, |
| 152 ApiDispatcher* dispatcher) { |
| 153 int tab_id = kInvalidChromeSessionId; |
| 154 HWND tab_handle = NULL; |
| 155 if (GetIdAndHandleFromArgs(input_args, &tab_id, &tab_handle)) { |
| 156 Singleton<ExecutorsManager, ExecutorsManager::SingletonTraits>::get()-> |
| 157 SetTabIdForHandle(tab_id, tab_handle); |
| 158 return true; |
| 159 } |
| 160 return false; |
| 161 } |
| 162 |
| 163 bool CeeeMapToolbandIdToHandle(const std::string& input_args, |
| 164 std::string* converted_args, |
| 165 ApiDispatcher* dispatcher) { |
| 166 int toolband_id = kInvalidChromeSessionId; |
| 167 HWND tab_handle = NULL; |
| 168 if (GetIdAndHandleFromArgs(input_args, &toolband_id, &tab_handle)) { |
| 169 Singleton<ExecutorsManager, ExecutorsManager::SingletonTraits>::get()-> |
| 170 SetTabToolBandIdForHandle(toolband_id, tab_handle); |
| 171 return true; |
| 172 } |
| 173 return false; |
| 174 } |
| 175 |
129 } // namespace | 176 } // namespace |
130 | 177 |
131 void RegisterInvocations(ApiDispatcher* dispatcher) { | 178 void RegisterInvocations(ApiDispatcher* dispatcher) { |
132 #define REGISTER_API_FUNCTION(func) do { dispatcher->RegisterInvocation(\ | 179 #define REGISTER_API_FUNCTION(func) do { dispatcher->RegisterInvocation(\ |
133 func##Function::function_name(), NewApiInvocation< func >); }\ | 180 func##Function::function_name(), NewApiInvocation< func >); }\ |
134 while (false) | 181 while (false) |
135 REGISTER_TAB_API_FUNCTIONS(); | 182 REGISTER_TAB_API_FUNCTIONS(); |
136 #undef REGISTER_API_FUNCTION | 183 #undef REGISTER_API_FUNCTION |
137 // Registers our private events. | 184 // Registers our private events. |
138 dispatcher->RegisterPermanentEventHandler( | 185 dispatcher->RegisterPermanentEventHandler( |
139 ceee_event_names::kCeeeOnTabUnmapped, CeeeUnmapTabEventHandler); | 186 ceee_event_names::kCeeeOnTabUnmapped, CeeeUnmapTabEventHandler); |
| 187 dispatcher->RegisterPermanentEventHandler( |
| 188 ceee_event_names::kCeeeMapTabIdToHandle, CeeeMapTabIdToHandle); |
| 189 dispatcher->RegisterPermanentEventHandler( |
| 190 ceee_event_names::kCeeeMapToolbandIdToHandle, CeeeMapToolbandIdToHandle); |
140 | 191 |
141 // And now register the permanent event handlers. | 192 // And now register the permanent event handlers. |
142 dispatcher->RegisterPermanentEventHandler(ext_event_names::kOnTabCreated, | 193 dispatcher->RegisterPermanentEventHandler(ext_event_names::kOnTabCreated, |
143 CreateTab::EventHandler); | 194 CreateTab::EventHandler); |
144 | 195 |
145 // For OnTabUpdate, we receive 2 from events_funnel, and add a Tab Parameter. | 196 // For OnTabUpdate, we receive 2 from events_funnel, and add a Tab Parameter. |
146 dispatcher->RegisterPermanentEventHandler(ext_event_names::kOnTabUpdated, | 197 dispatcher->RegisterPermanentEventHandler(ext_event_names::kOnTabUpdated, |
147 ConvertTabIdEventHandler<2, true>); | 198 ConvertTabIdEventHandler<2, true>); |
148 dispatcher->RegisterPermanentEventHandler(ext_event_names::kOnTabAttached, | 199 dispatcher->RegisterPermanentEventHandler(ext_event_names::kOnTabAttached, |
149 ConvertTabIdEventHandler<2, false>); | 200 ConvertTabIdEventHandler<2, false>); |
(...skipping 1131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1281 ::SysFreeString(title); | 1332 ::SysFreeString(title); |
1282 title = NULL; | 1333 title = NULL; |
1283 ::SysFreeString(fav_icon_url); | 1334 ::SysFreeString(fav_icon_url); |
1284 fav_icon_url = NULL; | 1335 fav_icon_url = NULL; |
1285 | 1336 |
1286 status = kCeeeTabStatusLoading; | 1337 status = kCeeeTabStatusLoading; |
1287 protected_mode = FALSE; | 1338 protected_mode = FALSE; |
1288 } | 1339 } |
1289 | 1340 |
1290 } // namespace tab_api | 1341 } // namespace tab_api |
OLD | NEW |