| 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 #include "chrome_frame/chrome_frame_activex.h" | 5 #include "chrome_frame/chrome_frame_activex.h" |
| 6 | 6 |
| 7 #include <wininet.h> | 7 #include <wininet.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <map> | 10 #include <map> |
| 11 | 11 |
| 12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/file_util.h" | 14 #include "base/file_util.h" |
| 15 #include "base/logging.h" | 15 #include "base/logging.h" |
| 16 #include "base/path_service.h" | 16 #include "base/path_service.h" |
| 17 #include "base/process_util.h" | 17 #include "base/process_util.h" |
| 18 #include "base/scoped_bstr_win.h" | |
| 19 #include "base/singleton.h" | 18 #include "base/singleton.h" |
| 20 #include "base/string_split.h" | 19 #include "base/string_split.h" |
| 21 #include "base/string_util.h" | 20 #include "base/string_util.h" |
| 22 #include "base/stringprintf.h" | 21 #include "base/stringprintf.h" |
| 23 #include "base/trace_event.h" | 22 #include "base/trace_event.h" |
| 24 #include "base/utf_string_conversions.h" | 23 #include "base/utf_string_conversions.h" |
| 24 #include "base/win/scoped_bstr.h" |
| 25 #include "base/win/scoped_variant.h" |
| 25 #include "chrome/common/chrome_constants.h" | 26 #include "chrome/common/chrome_constants.h" |
| 26 #include "chrome/common/chrome_switches.h" | 27 #include "chrome/common/chrome_switches.h" |
| 27 #include "chrome/test/automation/tab_proxy.h" | 28 #include "chrome/test/automation/tab_proxy.h" |
| 28 #include "googleurl/src/gurl.h" | 29 #include "googleurl/src/gurl.h" |
| 29 #include "chrome_frame/utils.h" | 30 #include "chrome_frame/utils.h" |
| 30 | 31 |
| 31 namespace { | 32 namespace { |
| 32 | 33 |
| 33 // Class used to maintain a mapping from top-level windows to ChromeFrameActivex | 34 // Class used to maintain a mapping from top-level windows to ChromeFrameActivex |
| 34 // instances. | 35 // instances. |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 DLOG(INFO) << __FUNCTION__; | 208 DLOG(INFO) << __FUNCTION__; |
| 208 | 209 |
| 209 if (target.compare("*") != 0) { | 210 if (target.compare("*") != 0) { |
| 210 bool drop = true; | 211 bool drop = true; |
| 211 | 212 |
| 212 if (is_privileged_) { | 213 if (is_privileged_) { |
| 213 // Forward messages if the control is in privileged mode. | 214 // Forward messages if the control is in privileged mode. |
| 214 ScopedComPtr<IDispatch> message_event; | 215 ScopedComPtr<IDispatch> message_event; |
| 215 if (SUCCEEDED(CreateDomEvent("message", message, origin, | 216 if (SUCCEEDED(CreateDomEvent("message", message, origin, |
| 216 message_event.Receive()))) { | 217 message_event.Receive()))) { |
| 217 ScopedBstr target_bstr(UTF8ToWide(target).c_str()); | 218 base::win::ScopedBstr target_bstr(UTF8ToWide(target).c_str()); |
| 218 Fire_onprivatemessage(message_event, target_bstr); | 219 Fire_onprivatemessage(message_event, target_bstr); |
| 219 | 220 |
| 220 FireEvent(onprivatemessage_, message_event, target_bstr); | 221 FireEvent(onprivatemessage_, message_event, target_bstr); |
| 221 } | 222 } |
| 222 } else { | 223 } else { |
| 223 if (HaveSameOrigin(target, document_url_)) { | 224 if (HaveSameOrigin(target, document_url_)) { |
| 224 drop = false; | 225 drop = false; |
| 225 } else { | 226 } else { |
| 226 DLOG(WARNING) << "Dropping posted message since target doesn't match " | 227 DLOG(WARNING) << "Dropping posted message since target doesn't match " |
| 227 "the current document's origin. target=" << target; | 228 "the current document's origin. target=" << target; |
| 228 } | 229 } |
| 229 } | 230 } |
| 230 | 231 |
| 231 if (drop) | 232 if (drop) |
| 232 return; | 233 return; |
| 233 } | 234 } |
| 234 | 235 |
| 235 ScopedComPtr<IDispatch> message_event; | 236 ScopedComPtr<IDispatch> message_event; |
| 236 if (SUCCEEDED(CreateDomEvent("message", message, origin, | 237 if (SUCCEEDED(CreateDomEvent("message", message, origin, |
| 237 message_event.Receive()))) { | 238 message_event.Receive()))) { |
| 238 Fire_onmessage(message_event); | 239 Fire_onmessage(message_event); |
| 239 | 240 |
| 240 FireEvent(onmessage_, message_event); | 241 FireEvent(onmessage_, message_event); |
| 241 | 242 |
| 242 ScopedVariant event_var; | 243 base::win::ScopedVariant event_var; |
| 243 event_var.Set(static_cast<IDispatch*>(message_event)); | 244 event_var.Set(static_cast<IDispatch*>(message_event)); |
| 244 InvokeScriptFunction(onmessage_handler_, event_var.AsInput()); | 245 InvokeScriptFunction(onmessage_handler_, event_var.AsInput()); |
| 245 } | 246 } |
| 246 } | 247 } |
| 247 | 248 |
| 248 void ChromeFrameActivex::OnAutomationServerLaunchFailed( | 249 void ChromeFrameActivex::OnAutomationServerLaunchFailed( |
| 249 AutomationLaunchResult reason, const std::string& server_version) { | 250 AutomationLaunchResult reason, const std::string& server_version) { |
| 250 Base::OnAutomationServerLaunchFailed(reason, server_version); | 251 Base::OnAutomationServerLaunchFailed(reason, server_version); |
| 251 | 252 |
| 252 if (reason == AUTOMATION_VERSION_MISMATCH) { | 253 if (reason == AUTOMATION_VERSION_MISMATCH) { |
| 253 DisplayVersionMismatchWarning(m_hWnd, server_version); | 254 DisplayVersionMismatchWarning(m_hWnd, server_version); |
| 254 } | 255 } |
| 255 } | 256 } |
| 256 | 257 |
| 257 void ChromeFrameActivex::OnExtensionInstalled( | 258 void ChromeFrameActivex::OnExtensionInstalled( |
| 258 const FilePath& path, | 259 const FilePath& path, |
| 259 void* user_data, | 260 void* user_data, |
| 260 AutomationMsg_ExtensionResponseValues response) { | 261 AutomationMsg_ExtensionResponseValues response) { |
| 261 ScopedBstr path_str(path.value().c_str()); | 262 base::win::ScopedBstr path_str(path.value().c_str()); |
| 262 Fire_onextensionready(path_str, response); | 263 Fire_onextensionready(path_str, response); |
| 263 } | 264 } |
| 264 | 265 |
| 265 void ChromeFrameActivex::OnGetEnabledExtensionsComplete( | 266 void ChromeFrameActivex::OnGetEnabledExtensionsComplete( |
| 266 void* user_data, | 267 void* user_data, |
| 267 const std::vector<FilePath>& extension_directories) { | 268 const std::vector<FilePath>& extension_directories) { |
| 268 SAFEARRAY* sa = ::SafeArrayCreateVector(VT_BSTR, 0, | 269 SAFEARRAY* sa = ::SafeArrayCreateVector(VT_BSTR, 0, |
| 269 extension_directories.size()); | 270 extension_directories.size()); |
| 270 sa->fFeatures = sa->fFeatures | FADF_BSTR; | 271 sa->fFeatures = sa->fFeatures | FADF_BSTR; |
| 271 ::SafeArrayLock(sa); | 272 ::SafeArrayLock(sa); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 STDMETHODIMP ChromeFrameActivex::Load(IPropertyBag* bag, IErrorLog* error_log) { | 307 STDMETHODIMP ChromeFrameActivex::Load(IPropertyBag* bag, IErrorLog* error_log) { |
| 307 DCHECK(bag); | 308 DCHECK(bag); |
| 308 | 309 |
| 309 const wchar_t* event_props[] = { | 310 const wchar_t* event_props[] = { |
| 310 (L"onload"), | 311 (L"onload"), |
| 311 (L"onloaderror"), | 312 (L"onloaderror"), |
| 312 (L"onmessage"), | 313 (L"onmessage"), |
| 313 (L"onreadystatechanged"), | 314 (L"onreadystatechanged"), |
| 314 }; | 315 }; |
| 315 | 316 |
| 316 ScopedComPtr<IHTMLObjectElement> obj_element; | 317 base::win::ScopedComPtr<IHTMLObjectElement> obj_element; |
| 317 GetObjectElement(obj_element.Receive()); | 318 GetObjectElement(obj_element.Receive()); |
| 318 | 319 |
| 319 ScopedBstr object_id; | 320 base::win::ScopedBstr object_id; |
| 320 GetObjectScriptId(obj_element, object_id.Receive()); | 321 GetObjectScriptId(obj_element, object_id.Receive()); |
| 321 | 322 |
| 322 ScopedComPtr<IHTMLElement2> element; | 323 ScopedComPtr<IHTMLElement2> element; |
| 323 element.QueryFrom(obj_element); | 324 element.QueryFrom(obj_element); |
| 324 HRESULT hr = S_OK; | 325 HRESULT hr = S_OK; |
| 325 | 326 |
| 326 for (int i = 0; SUCCEEDED(hr) && i < arraysize(event_props); ++i) { | 327 for (int i = 0; SUCCEEDED(hr) && i < arraysize(event_props); ++i) { |
| 327 ScopedBstr prop(event_props[i]); | 328 base::win::ScopedBstr prop(event_props[i]); |
| 328 ScopedVariant value; | 329 base::win::ScopedVariant value; |
| 329 if (SUCCEEDED(bag->Read(prop, value.Receive(), error_log))) { | 330 if (SUCCEEDED(bag->Read(prop, value.Receive(), error_log))) { |
| 330 if (value.type() != VT_BSTR || | 331 if (value.type() != VT_BSTR || |
| 331 FAILED(hr = CreateScriptBlockForEvent(element, object_id, | 332 FAILED(hr = CreateScriptBlockForEvent(element, object_id, |
| 332 V_BSTR(&value), prop))) { | 333 V_BSTR(&value), prop))) { |
| 333 DLOG(ERROR) << "Failed to create script block for " << prop | 334 DLOG(ERROR) << "Failed to create script block for " << prop |
| 334 << base::StringPrintf(L"hr=0x%08X, vt=%i", hr, | 335 << base::StringPrintf(L"hr=0x%08X, vt=%i", hr, |
| 335 value.type()); | 336 value.type()); |
| 336 } else { | 337 } else { |
| 337 DLOG(INFO) << "script block created for event " << prop << | 338 DLOG(INFO) << "script block created for event " << prop << |
| 338 base::StringPrintf(" (0x%08X)", hr) << " connections: " << | 339 base::StringPrintf(" (0x%08X)", hr) << " connections: " << |
| 339 ProxyDIChromeFrameEvents<ChromeFrameActivex>::m_vec.GetSize(); | 340 ProxyDIChromeFrameEvents<ChromeFrameActivex>::m_vec.GetSize(); |
| 340 } | 341 } |
| 341 } else { | 342 } else { |
| 342 DLOG(INFO) << "event property " << prop << " not in property bag"; | 343 DLOG(INFO) << "event property " << prop << " not in property bag"; |
| 343 } | 344 } |
| 344 } | 345 } |
| 345 | 346 |
| 346 ScopedVariant src; | 347 base::win::ScopedVariant src; |
| 347 if (SUCCEEDED(bag->Read(StackBstr(L"src"), src.Receive(), error_log))) { | 348 if (SUCCEEDED(bag->Read(base::win::ScopedBstr(L"src"), src.Receive(), |
| 349 error_log))) { |
| 348 if (src.type() == VT_BSTR) { | 350 if (src.type() == VT_BSTR) { |
| 349 hr = put_src(V_BSTR(&src)); | 351 hr = put_src(V_BSTR(&src)); |
| 350 DCHECK(hr != E_UNEXPECTED); | 352 DCHECK(hr != E_UNEXPECTED); |
| 351 } | 353 } |
| 352 } | 354 } |
| 353 | 355 |
| 354 ScopedVariant use_chrome_network; | 356 base::win::ScopedVariant use_chrome_network; |
| 355 if (SUCCEEDED(bag->Read(StackBstr(L"useChromeNetwork"), | 357 if (SUCCEEDED(bag->Read(base::win::ScopedBstr(L"useChromeNetwork"), |
| 356 use_chrome_network.Receive(), error_log))) { | 358 use_chrome_network.Receive(), error_log))) { |
| 357 VariantChangeType(use_chrome_network.AsInput(), | 359 VariantChangeType(use_chrome_network.AsInput(), |
| 358 use_chrome_network.AsInput(), | 360 use_chrome_network.AsInput(), |
| 359 0, VT_BOOL); | 361 0, VT_BOOL); |
| 360 if (use_chrome_network.type() == VT_BOOL) { | 362 if (use_chrome_network.type() == VT_BOOL) { |
| 361 hr = put_useChromeNetwork(V_BOOL(&use_chrome_network)); | 363 hr = put_useChromeNetwork(V_BOOL(&use_chrome_network)); |
| 362 DCHECK(hr != E_UNEXPECTED); | 364 DCHECK(hr != E_UNEXPECTED); |
| 363 } | 365 } |
| 364 } | 366 } |
| 365 | 367 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 424 if (SUCCEEDED(service_hr) && wants_privileged) | 426 if (SUCCEEDED(service_hr) && wants_privileged) |
| 425 is_privileged_ = true; | 427 is_privileged_ = true; |
| 426 | 428 |
| 427 url_fetcher_->set_privileged_mode(is_privileged_); | 429 url_fetcher_->set_privileged_mode(is_privileged_); |
| 428 } | 430 } |
| 429 | 431 |
| 430 std::wstring chrome_extra_arguments; | 432 std::wstring chrome_extra_arguments; |
| 431 std::wstring profile_name(GetHostProcessName(false)); | 433 std::wstring profile_name(GetHostProcessName(false)); |
| 432 if (is_privileged_) { | 434 if (is_privileged_) { |
| 433 // Does the host want to provide extra arguments? | 435 // Does the host want to provide extra arguments? |
| 434 ScopedBstr extra_arguments_arg; | 436 base::win::ScopedBstr extra_arguments_arg; |
| 435 service_hr = service->GetChromeExtraArguments( | 437 service_hr = service->GetChromeExtraArguments( |
| 436 extra_arguments_arg.Receive()); | 438 extra_arguments_arg.Receive()); |
| 437 if (S_OK == service_hr && extra_arguments_arg) | 439 if (S_OK == service_hr && extra_arguments_arg) |
| 438 chrome_extra_arguments.assign(extra_arguments_arg, | 440 chrome_extra_arguments.assign(extra_arguments_arg, |
| 439 extra_arguments_arg.Length()); | 441 extra_arguments_arg.Length()); |
| 440 | 442 |
| 441 ScopedBstr automated_functions_arg; | 443 ScopedBstr automated_functions_arg; |
| 442 service_hr = service->GetExtensionApisToAutomate( | 444 service_hr = service->GetExtensionApisToAutomate( |
| 443 automated_functions_arg.Receive()); | 445 automated_functions_arg.Receive()); |
| 444 if (S_OK == service_hr && automated_functions_arg) { | 446 if (S_OK == service_hr && automated_functions_arg) { |
| 445 std::string automated_functions( | 447 std::string automated_functions( |
| 446 WideToASCII(static_cast<BSTR>(automated_functions_arg))); | 448 WideToASCII(static_cast<BSTR>(automated_functions_arg))); |
| 447 functions_enabled_.clear(); | 449 functions_enabled_.clear(); |
| 448 // base::SplitString writes one empty entry for blank strings, so we | 450 // base::SplitString writes one empty entry for blank strings, so we |
| 449 // need this to allow specifying zero automation of API functions. | 451 // need this to allow specifying zero automation of API functions. |
| 450 if (!automated_functions.empty()) | 452 if (!automated_functions.empty()) |
| 451 base::SplitString(automated_functions, ',', &functions_enabled_); | 453 base::SplitString(automated_functions, ',', &functions_enabled_); |
| 452 } | 454 } |
| 453 | 455 |
| 454 ScopedBstr profile_name_arg; | 456 base::win::ScopedBstr profile_name_arg; |
| 455 service_hr = service->GetChromeProfileName(profile_name_arg.Receive()); | 457 service_hr = service->GetChromeProfileName(profile_name_arg.Receive()); |
| 456 if (S_OK == service_hr && profile_name_arg) | 458 if (S_OK == service_hr && profile_name_arg) |
| 457 profile_name.assign(profile_name_arg, profile_name_arg.Length()); | 459 profile_name.assign(profile_name_arg, profile_name_arg.Length()); |
| 458 } | 460 } |
| 459 | 461 |
| 460 std::string utf8_url; | 462 std::string utf8_url; |
| 461 if (url_.Length()) { | 463 if (url_.Length()) { |
| 462 WideToUTF8(url_, url_.Length(), &utf8_url); | 464 WideToUTF8(url_, url_.Length(), &utf8_url); |
| 463 } | 465 } |
| 464 | 466 |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 654 return hr; | 656 return hr; |
| 655 } | 657 } |
| 656 | 658 |
| 657 hr = bho->SetSite(web_browser2); | 659 hr = bho->SetSite(web_browser2); |
| 658 if (FAILED(hr)) { | 660 if (FAILED(hr)) { |
| 659 NOTREACHED() << "ChromeFrame BHO SetSite failed. Error:" | 661 NOTREACHED() << "ChromeFrame BHO SetSite failed. Error:" |
| 660 << base::StringPrintf(" 0x%08X", hr); | 662 << base::StringPrintf(" 0x%08X", hr); |
| 661 return hr; | 663 return hr; |
| 662 } | 664 } |
| 663 | 665 |
| 664 web_browser2->PutProperty(ScopedBstr(bho_class_id_as_string), | 666 web_browser2->PutProperty(base::win::ScopedBstr(bho_class_id_as_string), |
| 665 ScopedVariant(bho)); | 667 ScopedVariant(bho)); |
| 666 return S_OK; | 668 return S_OK; |
| 667 } | 669 } |
| OLD | NEW |