| 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 // Cookie API implementation. | 5 // Cookie API implementation. |
| 6 | 6 |
| 7 #include "ceee/ie/broker/cookie_api_module.h" | 7 #include "ceee/ie/broker/cookie_api_module.h" |
| 8 | 8 |
| 9 #include <atlbase.h> | 9 #include <atlbase.h> |
| 10 #include <atlcom.h> | 10 #include <atlcom.h> |
| 11 | 11 |
| 12 #include "base/json/json_reader.h" | 12 #include "base/json/json_reader.h" |
| 13 #include "base/json/json_writer.h" | 13 #include "base/json/json_writer.h" |
| 14 #include "base/scoped_comptr_win.h" | |
| 15 #include "base/string_util.h" | 14 #include "base/string_util.h" |
| 16 #include "base/win/scoped_bstr.h" | 15 #include "base/win/scoped_bstr.h" |
| 16 #include "base/win/scoped_comptr.h" |
| 17 #include "ceee/common/com_utils.h" | 17 #include "ceee/common/com_utils.h" |
| 18 #include "ceee/common/process_utils_win.h" | 18 #include "ceee/common/process_utils_win.h" |
| 19 #include "ceee/common/window_utils.h" | 19 #include "ceee/common/window_utils.h" |
| 20 #include "ceee/common/windows_constants.h" | 20 #include "ceee/common/windows_constants.h" |
| 21 #include "ceee/ie/broker/api_module_constants.h" | 21 #include "ceee/ie/broker/api_module_constants.h" |
| 22 #include "ceee/ie/broker/api_module_util.h" | 22 #include "ceee/ie/broker/api_module_util.h" |
| 23 #include "ceee/ie/broker/executors_manager.h" | 23 #include "ceee/ie/broker/executors_manager.h" |
| 24 #include "ceee/ie/broker/tab_api_module.h" | 24 #include "ceee/ie/broker/tab_api_module.h" |
| 25 #include "ceee/ie/broker/window_api_module.h" | 25 #include "ceee/ie/broker/window_api_module.h" |
| 26 #include "ceee/ie/common/api_registration.h" | 26 #include "ceee/ie/common/api_registration.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 DCHECK(value() == NULL); | 60 DCHECK(value() == NULL); |
| 61 set_value(cookie.release()); | 61 set_value(cookie.release()); |
| 62 return true; | 62 return true; |
| 63 } | 63 } |
| 64 | 64 |
| 65 bool CookieApiResult::GetTabListForWindow(HWND window, | 65 bool CookieApiResult::GetTabListForWindow(HWND window, |
| 66 scoped_ptr<ListValue>* tab_list) { | 66 scoped_ptr<ListValue>* tab_list) { |
| 67 DCHECK(tab_list); | 67 DCHECK(tab_list); |
| 68 ApiDispatcher* dispatcher = GetDispatcher(); | 68 ApiDispatcher* dispatcher = GetDispatcher(); |
| 69 DCHECK(dispatcher); | 69 DCHECK(dispatcher); |
| 70 ScopedComPtr<ICeeeWindowExecutor> executor; | 70 base::win::ScopedComPtr<ICeeeWindowExecutor> executor; |
| 71 dispatcher->GetExecutor(window, IID_ICeeeWindowExecutor, | 71 dispatcher->GetExecutor(window, IID_ICeeeWindowExecutor, |
| 72 reinterpret_cast<void**>(executor.Receive())); | 72 reinterpret_cast<void**>(executor.Receive())); |
| 73 if (executor == NULL) { | 73 if (executor == NULL) { |
| 74 LOG(WARNING) << "Failed to get an executor to get window tabs."; | 74 LOG(WARNING) << "Failed to get an executor to get window tabs."; |
| 75 return false; | 75 return false; |
| 76 } | 76 } |
| 77 base::win::ScopedBstr tab_handles; | 77 base::win::ScopedBstr tab_handles; |
| 78 HRESULT hr = executor->GetTabs(tab_handles.Receive()); | 78 HRESULT hr = executor->GetTabs(tab_handles.Receive()); |
| 79 if (FAILED(hr)) { | 79 if (FAILED(hr)) { |
| 80 // No DCHECK, this may happen if the window/thread dies on the way. | 80 // No DCHECK, this may happen if the window/thread dies on the way. |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 bool CookieApiResult::GetTabProtectedMode(HWND tab_window, | 127 bool CookieApiResult::GetTabProtectedMode(HWND tab_window, |
| 128 bool* is_protected_mode) { | 128 bool* is_protected_mode) { |
| 129 DCHECK(is_protected_mode); | 129 DCHECK(is_protected_mode); |
| 130 if (!ExecutorsManager::IsKnownWindow(tab_window) || | 130 if (!ExecutorsManager::IsKnownWindow(tab_window) || |
| 131 window_utils::WindowHasNoThread(tab_window) || | 131 window_utils::WindowHasNoThread(tab_window) || |
| 132 !window_utils::IsWindowClass(tab_window, windows::kIeTabWindowClass)) { | 132 !window_utils::IsWindowClass(tab_window, windows::kIeTabWindowClass)) { |
| 133 return false; | 133 return false; |
| 134 } | 134 } |
| 135 ApiDispatcher* dispatcher = GetDispatcher(); | 135 ApiDispatcher* dispatcher = GetDispatcher(); |
| 136 DCHECK(dispatcher); | 136 DCHECK(dispatcher); |
| 137 ScopedComPtr<ICeeeTabExecutor> executor; | 137 base::win::ScopedComPtr<ICeeeTabExecutor> executor; |
| 138 dispatcher->GetExecutor(tab_window, IID_ICeeeTabExecutor, | 138 dispatcher->GetExecutor(tab_window, IID_ICeeeTabExecutor, |
| 139 reinterpret_cast<void**>(executor.Receive())); | 139 reinterpret_cast<void**>(executor.Receive())); |
| 140 if (executor == NULL) { | 140 if (executor == NULL) { |
| 141 LOG(WARNING) << "Failed to get an executor to get tab info."; | 141 LOG(WARNING) << "Failed to get an executor to get tab info."; |
| 142 return false; | 142 return false; |
| 143 } | 143 } |
| 144 tab_api::TabInfo tab_info; | 144 tab_api::TabInfo tab_info; |
| 145 HRESULT hr = executor->GetTabInfo(&tab_info); | 145 HRESULT hr = executor->GetTabInfo(&tab_info); |
| 146 if (FAILED(hr)) { | 146 if (FAILED(hr)) { |
| 147 LOG(WARNING) << "Executor failed to get tab info." << com::LogHr(hr); | 147 LOG(WARNING) << "Executor failed to get tab info." << com::LogHr(hr); |
| 148 return false; | 148 return false; |
| 149 } | 149 } |
| 150 *is_protected_mode = !!tab_info.protected_mode; | 150 *is_protected_mode = !!tab_info.protected_mode; |
| 151 return true; | 151 return true; |
| 152 } | 152 } |
| 153 | 153 |
| 154 HRESULT CookieApiResult::GetCookieInfo( | 154 HRESULT CookieApiResult::GetCookieInfo( |
| 155 const std::string& url, const std::string& name, HWND window, | 155 const std::string& url, const std::string& name, HWND window, |
| 156 bool is_protected_mode, CookieInfo* cookie_info) { | 156 bool is_protected_mode, CookieInfo* cookie_info) { |
| 157 // Get a tab window child of the cookie store window, so that we can properly | 157 // Get a tab window child of the cookie store window, so that we can properly |
| 158 // access session cookies. | 158 // access session cookies. |
| 159 HWND tab_window = GetAnyTabInWindow(window, is_protected_mode); | 159 HWND tab_window = GetAnyTabInWindow(window, is_protected_mode); |
| 160 if (tab_window == NULL) { | 160 if (tab_window == NULL) { |
| 161 PostError("Failed to get tab window for a given cookie store."); | 161 PostError("Failed to get tab window for a given cookie store."); |
| 162 return E_FAIL; | 162 return E_FAIL; |
| 163 } | 163 } |
| 164 | 164 |
| 165 ApiDispatcher* dispatcher = GetDispatcher(); | 165 ApiDispatcher* dispatcher = GetDispatcher(); |
| 166 DCHECK(dispatcher); | 166 DCHECK(dispatcher); |
| 167 ScopedComPtr<ICeeeCookieExecutor> executor; | 167 base::win::ScopedComPtr<ICeeeCookieExecutor> executor; |
| 168 dispatcher->GetExecutor(tab_window, IID_ICeeeCookieExecutor, | 168 dispatcher->GetExecutor(tab_window, IID_ICeeeCookieExecutor, |
| 169 reinterpret_cast<void**>(executor.Receive())); | 169 reinterpret_cast<void**>(executor.Receive())); |
| 170 if (executor == NULL) { | 170 if (executor == NULL) { |
| 171 LOG(WARNING) << "Failed to get an executor to get cookie info."; | 171 LOG(WARNING) << "Failed to get an executor to get cookie info."; |
| 172 PostError("Internal Error while getting cookie info."); | 172 PostError("Internal Error while getting cookie info."); |
| 173 return E_FAIL; | 173 return E_FAIL; |
| 174 } | 174 } |
| 175 | 175 |
| 176 HRESULT hr = executor->GetCookie( | 176 HRESULT hr = executor->GetCookie( |
| 177 CComBSTR(url.data()), CComBSTR(name.data()), cookie_info); | 177 CComBSTR(url.data()), CComBSTR(name.data()), cookie_info); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 cookie_store->Set(keys::kTabIdsKey, protected_tab_ids.release()); | 222 cookie_store->Set(keys::kTabIdsKey, protected_tab_ids.release()); |
| 223 set_value(cookie_store.release()); | 223 set_value(cookie_store.release()); |
| 224 PostResult(); | 224 PostResult(); |
| 225 } | 225 } |
| 226 return true; | 226 return true; |
| 227 } | 227 } |
| 228 | 228 |
| 229 HRESULT CookieApiResult::RegisterCookieStore(HWND window) { | 229 HRESULT CookieApiResult::RegisterCookieStore(HWND window) { |
| 230 ApiDispatcher* dispatcher = GetDispatcher(); | 230 ApiDispatcher* dispatcher = GetDispatcher(); |
| 231 DCHECK(dispatcher); | 231 DCHECK(dispatcher); |
| 232 ScopedComPtr<ICeeeCookieExecutor> executor; | 232 base::win::ScopedComPtr<ICeeeCookieExecutor> executor; |
| 233 dispatcher->GetExecutor(window, IID_ICeeeCookieExecutor, | 233 dispatcher->GetExecutor(window, IID_ICeeeCookieExecutor, |
| 234 reinterpret_cast<void**>(executor.Receive())); | 234 reinterpret_cast<void**>(executor.Receive())); |
| 235 if (executor == NULL) { | 235 if (executor == NULL) { |
| 236 LOG(WARNING) << "Failed to get an executor to register a cookie store."; | 236 LOG(WARNING) << "Failed to get an executor to register a cookie store."; |
| 237 PostError(api_module_constants::kInternalErrorError); | 237 PostError(api_module_constants::kInternalErrorError); |
| 238 return E_FAIL; | 238 return E_FAIL; |
| 239 } | 239 } |
| 240 HRESULT hr = executor->RegisterCookieStore(); | 240 HRESULT hr = executor->RegisterCookieStore(); |
| 241 if (FAILED(hr)) { | 241 if (FAILED(hr)) { |
| 242 // No DCHECK, this may happen if the window/thread dies on the way. | 242 // No DCHECK, this may happen if the window/thread dies on the way. |
| 243 LOG(ERROR) << "Can't register cookie store. " << com::LogHr(hr); | 243 LOG(ERROR) << "Can't register cookie store. " << com::LogHr(hr); |
| 244 PostError(api_module_constants::kInternalErrorError); | 244 PostError(api_module_constants::kInternalErrorError); |
| 245 } | 245 } |
| 246 return hr; | 246 return hr; |
| 247 } | 247 } |
| 248 | 248 |
| 249 HRESULT CookieApiResult::CookieStoreIsRegistered(HWND window) { | 249 HRESULT CookieApiResult::CookieStoreIsRegistered(HWND window) { |
| 250 ApiDispatcher* dispatcher = GetDispatcher(); | 250 ApiDispatcher* dispatcher = GetDispatcher(); |
| 251 DCHECK(dispatcher); | 251 DCHECK(dispatcher); |
| 252 ScopedComPtr<ICeeeCookieExecutor> executor; | 252 base::win::ScopedComPtr<ICeeeCookieExecutor> executor; |
| 253 dispatcher->GetExecutor(window, IID_ICeeeCookieExecutor, | 253 dispatcher->GetExecutor(window, IID_ICeeeCookieExecutor, |
| 254 reinterpret_cast<void**>(executor.Receive())); | 254 reinterpret_cast<void**>(executor.Receive())); |
| 255 if (executor == NULL) { | 255 if (executor == NULL) { |
| 256 LOG(WARNING) << "Failed to get an executor to register a cookie store."; | 256 LOG(WARNING) << "Failed to get an executor to register a cookie store."; |
| 257 PostError(api_module_constants::kInternalErrorError); | 257 PostError(api_module_constants::kInternalErrorError); |
| 258 return E_FAIL; | 258 return E_FAIL; |
| 259 } | 259 } |
| 260 HRESULT hr = executor->CookieStoreIsRegistered(); | 260 HRESULT hr = executor->CookieStoreIsRegistered(); |
| 261 if (FAILED(hr)) { | 261 if (FAILED(hr)) { |
| 262 // No DCHECK, this may happen if the window/thread dies on the way. | 262 // No DCHECK, this may happen if the window/thread dies on the way. |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 575 CookieInfo::~CookieInfo() { | 575 CookieInfo::~CookieInfo() { |
| 576 // SysFreeString accepts NULL pointers. | 576 // SysFreeString accepts NULL pointers. |
| 577 ::SysFreeString(name); | 577 ::SysFreeString(name); |
| 578 ::SysFreeString(value); | 578 ::SysFreeString(value); |
| 579 ::SysFreeString(domain); | 579 ::SysFreeString(domain); |
| 580 ::SysFreeString(path); | 580 ::SysFreeString(path); |
| 581 ::SysFreeString(store_id); | 581 ::SysFreeString(store_id); |
| 582 } | 582 } |
| 583 | 583 |
| 584 } // namespace cookie_api | 584 } // namespace cookie_api |
| OLD | NEW |