| 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 // Dispatcher and registry for Chrome Extension APIs. | 5 // Dispatcher and registry for Chrome Extension APIs. |
| 6 | 6 |
| 7 #include "ceee/ie/broker/api_dispatcher.h" | 7 #include "ceee/ie/broker/api_dispatcher.h" |
| 8 | 8 |
| 9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
| 10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 if (list_iter->handler(converted_event_args, | 135 if (list_iter->handler(converted_event_args, |
| 136 list_iter->user_data, this) == S_FALSE) { | 136 list_iter->user_data, this) == S_FALSE) { |
| 137 map_iter->second.push_back(*list_iter); | 137 map_iter->second.push_back(*list_iter); |
| 138 } | 138 } |
| 139 } | 139 } |
| 140 } | 140 } |
| 141 } | 141 } |
| 142 | 142 |
| 143 void ApiDispatcher::GetExecutor(HWND window, REFIID iid, void** executor) { | 143 void ApiDispatcher::GetExecutor(HWND window, REFIID iid, void** executor) { |
| 144 DWORD thread_id = ::GetWindowThreadProcessId(window, NULL); | 144 DWORD thread_id = ::GetWindowThreadProcessId(window, NULL); |
| 145 HRESULT hr = Singleton<ExecutorsManager, | 145 HRESULT hr = ExecutorsManager::GetInstance()->GetExecutor(thread_id, window, |
| 146 ExecutorsManager::SingletonTraits>::get()-> | 146 iid, executor); |
| 147 GetExecutor(thread_id, window, iid, executor); | |
| 148 DLOG_IF(INFO, FAILED(hr)) << "Failed to get executor for window: " << | 147 DLOG_IF(INFO, FAILED(hr)) << "Failed to get executor for window: " << |
| 149 window << ". In thread: " << thread_id << ". " << com::LogHr(hr); | 148 window << ". In thread: " << thread_id << ". " << com::LogHr(hr); |
| 150 } | 149 } |
| 151 | 150 |
| 152 bool ApiDispatcher::IsTabIdValid(int tab_id) const { | 151 bool ApiDispatcher::IsTabIdValid(int tab_id) const { |
| 153 return Singleton<ExecutorsManager, ExecutorsManager::SingletonTraits>::get()-> | 152 return ExecutorsManager::GetInstance()->IsTabIdValid(tab_id); |
| 154 IsTabIdValid(tab_id); | |
| 155 } | 153 } |
| 156 | 154 |
| 157 HWND ApiDispatcher::GetTabHandleFromId(int tab_id) const { | 155 HWND ApiDispatcher::GetTabHandleFromId(int tab_id) const { |
| 158 return Singleton<ExecutorsManager, ExecutorsManager::SingletonTraits>::get()-> | 156 return ExecutorsManager::GetInstance()->GetTabHandleFromId(tab_id); |
| 159 GetTabHandleFromId(tab_id); | |
| 160 } | 157 } |
| 161 | 158 |
| 162 HWND ApiDispatcher::GetTabHandleFromToolBandId(int tool_band_id) const { | 159 HWND ApiDispatcher::GetTabHandleFromToolBandId(int tool_band_id) const { |
| 163 return Singleton<ExecutorsManager, ExecutorsManager::SingletonTraits>::get()-> | 160 return ExecutorsManager::GetInstance()->GetTabHandleFromToolBandId( |
| 164 GetTabHandleFromToolBandId(tool_band_id); | 161 tool_band_id); |
| 165 } | 162 } |
| 166 | 163 |
| 167 HWND ApiDispatcher::GetWindowHandleFromId(int window_id) const { | 164 HWND ApiDispatcher::GetWindowHandleFromId(int window_id) const { |
| 168 return reinterpret_cast<HWND>(window_id); | 165 return reinterpret_cast<HWND>(window_id); |
| 169 } | 166 } |
| 170 | 167 |
| 171 bool ApiDispatcher::IsTabHandleValid(HWND tab_handle) const { | 168 bool ApiDispatcher::IsTabHandleValid(HWND tab_handle) const { |
| 172 return Singleton<ExecutorsManager, ExecutorsManager::SingletonTraits>::get()-> | 169 return ExecutorsManager::GetInstance()->IsTabHandleValid(tab_handle); |
| 173 IsTabHandleValid(tab_handle); | |
| 174 } | 170 } |
| 175 | 171 |
| 176 int ApiDispatcher::GetTabIdFromHandle(HWND tab_handle) const { | 172 int ApiDispatcher::GetTabIdFromHandle(HWND tab_handle) const { |
| 177 return Singleton<ExecutorsManager, ExecutorsManager::SingletonTraits>::get()-> | 173 return ExecutorsManager::GetInstance()->GetTabIdFromHandle(tab_handle); |
| 178 GetTabIdFromHandle(tab_handle); | |
| 179 } | 174 } |
| 180 | 175 |
| 181 int ApiDispatcher::GetWindowIdFromHandle(HWND window_handle) const { | 176 int ApiDispatcher::GetWindowIdFromHandle(HWND window_handle) const { |
| 182 return reinterpret_cast<int>(window_handle); | 177 return reinterpret_cast<int>(window_handle); |
| 183 } | 178 } |
| 184 | 179 |
| 185 void ApiDispatcher::DeleteTabHandle(HWND handle) { | 180 void ApiDispatcher::DeleteTabHandle(HWND handle) { |
| 186 Singleton<ExecutorsManager, ExecutorsManager::SingletonTraits>::get()-> | 181 ExecutorsManager::GetInstance()->DeleteTabHandle(handle); |
| 187 DeleteTabHandle(handle); | |
| 188 } | 182 } |
| 189 | 183 |
| 190 void ApiDispatcher::RegisterInvocation(const char* function_name, | 184 void ApiDispatcher::RegisterInvocation(const char* function_name, |
| 191 InvocationFactory factory) { | 185 InvocationFactory factory) { |
| 192 DCHECK(function_name && factory); | 186 DCHECK(function_name && factory); |
| 193 // Re-registration is not expected. | 187 // Re-registration is not expected. |
| 194 DCHECK(function_name && factories_.find(function_name) == factories_.end()); | 188 DCHECK(function_name && factories_.find(function_name) == factories_.end()); |
| 195 if (function_name && factory) | 189 if (function_name && factory) |
| 196 factories_[function_name] = factory; | 190 factories_[function_name] = factory; |
| 197 } | 191 } |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 return NULL; | 284 return NULL; |
| 291 | 285 |
| 292 Value* value = NULL; | 286 Value* value = NULL; |
| 293 bool success = temp_values_->Get(name, &value); | 287 bool success = temp_values_->Get(name, &value); |
| 294 // Make sure that success means NotNull and vice versa. | 288 // Make sure that success means NotNull and vice versa. |
| 295 DCHECK((value != NULL || !success) && (success || value == NULL)); | 289 DCHECK((value != NULL || !success) && (success || value == NULL)); |
| 296 return value; | 290 return value; |
| 297 } | 291 } |
| 298 | 292 |
| 299 ApiDispatcher* ApiDispatcher::InvocationResult::GetDispatcher() { | 293 ApiDispatcher* ApiDispatcher::InvocationResult::GetDispatcher() { |
| 300 return ProductionApiDispatcher::get(); | 294 return ProductionApiDispatcher::GetInstance(); |
| 301 } | 295 } |
| 302 | 296 |
| 303 ApiDispatcher* ApiDispatcher::Invocation::GetDispatcher() { | 297 ApiDispatcher* ApiDispatcher::Invocation::GetDispatcher() { |
| 304 return ProductionApiDispatcher::get(); | 298 return ProductionApiDispatcher::GetInstance(); |
| 305 } | 299 } |
| 306 | 300 |
| 307 // Function registration preprocessor magic. See api_registration.h for details. | 301 // Function registration preprocessor magic. See api_registration.h for details. |
| 308 #ifdef REGISTER_ALL_API_FUNCTIONS | 302 #ifdef REGISTER_ALL_API_FUNCTIONS |
| 309 #error Must not include api_registration.h previously in this compilation unit. | 303 #error Must not include api_registration.h previously in this compilation unit. |
| 310 #endif // REGISTER_ALL_API_FUNCTIONS | 304 #endif // REGISTER_ALL_API_FUNCTIONS |
| 311 #define PRODUCTION_API_DISPATCHER | 305 #define PRODUCTION_API_DISPATCHER |
| 312 #define REGISTER_TAB_API_FUNCTIONS() tab_api::RegisterInvocations(this) | 306 #define REGISTER_TAB_API_FUNCTIONS() tab_api::RegisterInvocations(this) |
| 313 #define REGISTER_WINDOW_API_FUNCTIONS() window_api::RegisterInvocations(this) | 307 #define REGISTER_WINDOW_API_FUNCTIONS() window_api::RegisterInvocations(this) |
| 314 #define REGISTER_COOKIE_API_FUNCTIONS() cookie_api::RegisterInvocations(this) | 308 #define REGISTER_COOKIE_API_FUNCTIONS() cookie_api::RegisterInvocations(this) |
| 315 #define REGISTER_INFOBAR_API_FUNCTIONS() infobar_api::RegisterInvocations(this) | 309 #define REGISTER_INFOBAR_API_FUNCTIONS() infobar_api::RegisterInvocations(this) |
| 316 #define REGISTER_WEBNAVIGATION_API_FUNCTIONS() \ | 310 #define REGISTER_WEBNAVIGATION_API_FUNCTIONS() \ |
| 317 webnavigation_api::RegisterInvocations(this) | 311 webnavigation_api::RegisterInvocations(this) |
| 318 #define REGISTER_WEBREQUEST_API_FUNCTIONS() \ | 312 #define REGISTER_WEBREQUEST_API_FUNCTIONS() \ |
| 319 webrequest_api::RegisterInvocations(this) | 313 webrequest_api::RegisterInvocations(this) |
| 320 #include "ceee/ie/common/api_registration.h" | 314 #include "ceee/ie/common/api_registration.h" |
| 321 | 315 |
| 322 ProductionApiDispatcher::ProductionApiDispatcher() { | 316 ProductionApiDispatcher::ProductionApiDispatcher() { |
| 323 REGISTER_ALL_API_FUNCTIONS(); | 317 REGISTER_ALL_API_FUNCTIONS(); |
| 324 } | 318 } |
| 319 |
| 320 // static |
| 321 ProductionApiDispatcher* ProductionApiDispatcher::GetInstance() { |
| 322 return Singleton<ProductionApiDispatcher>::get(); |
| 323 } |
| OLD | NEW |