| 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 // IE browser helper object implementation. | 5 // IE browser helper object implementation. |
| 6 #include "ceee/ie/plugin/bho/browser_helper_object.h" | 6 #include "ceee/ie/plugin/bho/browser_helper_object.h" |
| 7 | 7 |
| 8 #include <atlsafe.h> | 8 #include <atlsafe.h> |
| 9 #include <shlguid.h> | 9 #include <shlguid.h> |
| 10 | 10 |
| 11 #include <algorithm> | 11 #include <algorithm> |
| 12 | 12 |
| 13 #include "base/debug/trace_event.h" | 13 #include "base/debug/trace_event.h" |
| 14 #include "base/json/json_reader.h" | 14 #include "base/json/json_reader.h" |
| 15 #include "base/json/json_writer.h" |
| 15 #include "base/logging.h" | 16 #include "base/logging.h" |
| 16 #include "base/string_util.h" | 17 #include "base/string_util.h" |
| 17 #include "base/tuple.h" | 18 #include "base/tuple.h" |
| 18 #include "base/utf_string_conversions.h" | 19 #include "base/utf_string_conversions.h" |
| 19 #include "ceee/common/com_utils.h" | 20 #include "ceee/common/com_utils.h" |
| 20 #include "ceee/common/window_utils.h" | 21 #include "ceee/common/window_utils.h" |
| 21 #include "ceee/common/windows_constants.h" | 22 #include "ceee/common/windows_constants.h" |
| 22 #include "ceee/ie/broker/tab_api_module.h" | 23 #include "ceee/ie/broker/tab_api_module.h" |
| 24 #include "ceee/ie/common/constants.h" |
| 23 #include "ceee/ie/common/extension_manifest.h" | 25 #include "ceee/ie/common/extension_manifest.h" |
| 24 #include "ceee/ie/common/ie_util.h" | 26 #include "ceee/ie/common/ie_util.h" |
| 25 #include "ceee/ie/common/metrics_util.h" | 27 #include "ceee/ie/common/metrics_util.h" |
| 26 #include "ceee/ie/common/ceee_module_util.h" | 28 #include "ceee/ie/common/ceee_module_util.h" |
| 27 #include "ceee/ie/plugin/bho/cookie_accountant.h" | 29 #include "ceee/ie/plugin/bho/cookie_accountant.h" |
| 28 #include "ceee/ie/plugin/bho/http_negotiate.h" | 30 #include "ceee/ie/plugin/bho/http_negotiate.h" |
| 29 #include "ceee/ie/plugin/scripting/script_host.h" | 31 #include "ceee/ie/plugin/scripting/script_host.h" |
| 30 #include "ceee/ie/plugin/toolband/toolband_proxy.h" | 32 #include "ceee/ie/plugin/toolband/toolband_proxy.h" |
| 31 #include "chrome/browser/automation/extension_automation_constants.h" | 33 #include "chrome/browser/automation/extension_automation_constants.h" |
| 32 #include "chrome/browser/extensions/extension_tabs_module_constants.h" | 34 #include "chrome/browser/extensions/extension_tabs_module_constants.h" |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 } | 312 } |
| 311 | 313 |
| 312 HRESULT BrowserHelperObject::UnregisterExecutor(DWORD thread_id) { | 314 HRESULT BrowserHelperObject::UnregisterExecutor(DWORD thread_id) { |
| 313 base::win::ScopedComPtr<ICeeeBrokerRegistrar> registrar; | 315 base::win::ScopedComPtr<ICeeeBrokerRegistrar> registrar; |
| 314 HRESULT hr = GetBrokerRegistrar(registrar.Receive()); | 316 HRESULT hr = GetBrokerRegistrar(registrar.Receive()); |
| 315 if (FAILED(hr)) | 317 if (FAILED(hr)) |
| 316 return hr; | 318 return hr; |
| 317 return registrar->UnregisterExecutor(thread_id); | 319 return registrar->UnregisterExecutor(thread_id); |
| 318 } | 320 } |
| 319 | 321 |
| 320 HRESULT BrowserHelperObject::SetTabToolBandIdForHandle(int tool_band_id, | |
| 321 long tab_handle) { | |
| 322 base::win::ScopedComPtr<ICeeeBrokerRegistrar> registrar; | |
| 323 HRESULT hr = GetBrokerRegistrar(registrar.Receive()); | |
| 324 if (FAILED(hr)) | |
| 325 return hr; | |
| 326 return registrar->SetTabToolBandIdForHandle(tool_band_id, tab_handle); | |
| 327 } | |
| 328 | |
| 329 HRESULT BrowserHelperObject::SetTabIdForHandle(int tool_band_id, | |
| 330 long tab_handle) { | |
| 331 base::win::ScopedComPtr<ICeeeBrokerRegistrar> registrar; | |
| 332 HRESULT hr = GetBrokerRegistrar(registrar.Receive()); | |
| 333 if (FAILED(hr)) | |
| 334 return hr; | |
| 335 return registrar->SetTabIdForHandle(tool_band_id, tab_handle); | |
| 336 } | |
| 337 | |
| 338 HRESULT BrowserHelperObject::Initialize(IUnknown* site) { | 322 HRESULT BrowserHelperObject::Initialize(IUnknown* site) { |
| 339 TRACE_EVENT_INSTANT("ceee.bho.initialize", this, ""); | 323 TRACE_EVENT_INSTANT("ceee.bho.initialize", this, ""); |
| 340 mu::ScopedTimer metrics_timer("ceee/BHO.Initialize", &broker_rpc()); | 324 mu::ScopedTimer metrics_timer("ceee/BHO.Initialize", &broker_rpc()); |
| 341 | 325 |
| 342 HRESULT hr = ConnectRpcBrokerClient(); | 326 HRESULT hr = ConnectRpcBrokerClient(); |
| 343 if (FAILED(hr) || !broker_rpc().is_connected()) { | 327 if (FAILED(hr) || !broker_rpc().is_connected()) { |
| 344 // Cancel the logging. The BrokerRpcClient isn't ready. | 328 // Cancel the logging. The BrokerRpcClient isn't ready. |
| 345 metrics_timer.Drop(); | 329 metrics_timer.Drop(); |
| 346 NOTREACHED() << "Couldn't connect to the RPC server."; | 330 NOTREACHED() << "Couldn't connect to the RPC server."; |
| 347 return com::AlwaysError(hr); | 331 return com::AlwaysError(hr); |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 629 return false; | 613 return false; |
| 630 } | 614 } |
| 631 | 615 |
| 632 // At this point if tab_id_ is still invalid we have a problem. | 616 // At this point if tab_id_ is still invalid we have a problem. |
| 633 if (tab_id_ == kInvalidChromeSessionId) { | 617 if (tab_id_ == kInvalidChromeSessionId) { |
| 634 // Something really bad happened. | 618 // Something really bad happened. |
| 635 NOTREACHED(); | 619 NOTREACHED(); |
| 636 return false; | 620 return false; |
| 637 } | 621 } |
| 638 | 622 |
| 639 CeeeWindowHandle handle = reinterpret_cast<CeeeWindowHandle>(tab_window_); | 623 hr = FireMapTabIdToHandle(); |
| 640 hr = SetTabIdForHandle(tab_id_, handle); | |
| 641 if (FAILED(hr)) { | 624 if (FAILED(hr)) { |
| 642 DCHECK(SUCCEEDED(hr)) << "An error occured when setting the tab_id: " << | 625 DCHECK(SUCCEEDED(hr)) << "An error occured when setting the tab_id: " << |
| 643 com::LogHr(hr); | 626 com::LogHr(hr); |
| 644 tab_id_ = kInvalidChromeSessionId; | 627 tab_id_ = kInvalidChromeSessionId; |
| 645 return false; | 628 return false; |
| 646 } | 629 } |
| 647 VLOG(2) << "TabId(" << tab_id_ << ") set for Handle(" << handle << ")"; | 630 VLOG(2) << "TabId(" << tab_id_ << ") set for Handle(" << tab_window_ << ")"; |
| 648 | 631 |
| 649 // Call back all the events we deferred. In order, please. | 632 // Call back all the events we deferred. In order, please. |
| 650 while (!deferred_events_call_.empty()) { | 633 while (!deferred_events_call_.empty()) { |
| 651 // We pop here so that if an error happens in the call we don't recall the | 634 // We pop here so that if an error happens in the call we don't recall the |
| 652 // faulty method. This has the side-effect of losing events. | 635 // faulty method. This has the side-effect of losing events. |
| 653 DeferredCallListType::value_type call = deferred_events_call_.front(); | 636 DeferredCallListType::value_type call = deferred_events_call_.front(); |
| 654 deferred_events_call_.pop_front(); | 637 deferred_events_call_.pop_front(); |
| 655 call->Run(); | 638 call->Run(); |
| 656 delete call; | 639 delete call; |
| 657 } | 640 } |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 706 return hr; | 689 return hr; |
| 707 } | 690 } |
| 708 return hr; | 691 return hr; |
| 709 } | 692 } |
| 710 | 693 |
| 711 HRESULT BrowserHelperObject::CreateChromeFrameHost() { | 694 HRESULT BrowserHelperObject::CreateChromeFrameHost() { |
| 712 return ChromeFrameHost::CreateInitializedIID(chrome_frame_host_.iid(), | 695 return ChromeFrameHost::CreateInitializedIID(chrome_frame_host_.iid(), |
| 713 chrome_frame_host_.Receive()); | 696 chrome_frame_host_.Receive()); |
| 714 } | 697 } |
| 715 | 698 |
| 699 HRESULT BrowserHelperObject::SendIdMappingToBroker(const char* event_name, |
| 700 int id) { |
| 701 // Event arguments for FireEvent need to be stored in a list. |
| 702 VLOG(1) << "SendIdMappingToBroker(" << event_name << ", " << id << ")"; |
| 703 DCHECK(id != kInvalidChromeSessionId); |
| 704 DCHECK(tab_window_ != NULL); |
| 705 |
| 706 ListValue mapping_args; |
| 707 mapping_args.Append(Value::CreateIntegerValue(id)); |
| 708 mapping_args.Append(Value::CreateIntegerValue( |
| 709 reinterpret_cast<int>(tab_window_))); |
| 710 |
| 711 std::string event_args_str; |
| 712 base::JSONWriter::Write(&mapping_args, false, &event_args_str); |
| 713 // We go directly to Impl version since we know we have Ensured Id... |
| 714 return SendEventToBrokerImpl(event_name, event_args_str); |
| 715 } |
| 716 |
| 717 HRESULT BrowserHelperObject::FireMapTabIdToHandle() { |
| 718 return SendIdMappingToBroker(ceee_event_names::kCeeeMapTabIdToHandle, |
| 719 tab_id_); |
| 720 } |
| 721 |
| 722 HRESULT BrowserHelperObject::FireMapToolbandIdToHandle(int toolband_id) { |
| 723 return SendIdMappingToBroker(ceee_event_names::kCeeeMapToolbandIdToHandle, |
| 724 toolband_id); |
| 725 } |
| 726 |
| 716 void BrowserHelperObject::FireOnCreatedEvent(BSTR url) { | 727 void BrowserHelperObject::FireOnCreatedEvent(BSTR url) { |
| 717 DCHECK(url != NULL); | 728 DCHECK(url != NULL); |
| 718 DCHECK(tab_window_ != NULL); | 729 DCHECK(tab_window_ != NULL); |
| 719 DCHECK(!fired_on_created_event_); | 730 DCHECK(!fired_on_created_event_); |
| 720 // Avoid sending double-creation events. Also only fire the event if we're | 731 // Avoid sending double-creation events. Also only fire the event if we're |
| 721 // NOT in full-tab mode, because by design, extensions are not supposed to be | 732 // NOT in full-tab mode, because by design, extensions are not supposed to be |
| 722 // aware of full-tab Chrome Frame tabs. | 733 // aware of full-tab Chrome Frame tabs. |
| 723 if (fired_on_created_event_ || full_tab_chrome_frame_) | 734 if (fired_on_created_event_ || full_tab_chrome_frame_) |
| 724 return; | 735 return; |
| 725 | 736 |
| (...skipping 832 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1558 if (sink == NULL) | 1569 if (sink == NULL) |
| 1559 return; | 1570 return; |
| 1560 | 1571 |
| 1561 std::vector<Sink*>::iterator iter = std::find(sinks_.begin(), sinks_.end(), | 1572 std::vector<Sink*>::iterator iter = std::find(sinks_.begin(), sinks_.end(), |
| 1562 sink); | 1573 sink); |
| 1563 if (iter != sinks_.end()) | 1574 if (iter != sinks_.end()) |
| 1564 sinks_.erase(iter); | 1575 sinks_.erase(iter); |
| 1565 } | 1576 } |
| 1566 | 1577 |
| 1567 STDMETHODIMP BrowserHelperObject::SetToolBandSessionId(long session_id) { | 1578 STDMETHODIMP BrowserHelperObject::SetToolBandSessionId(long session_id) { |
| 1568 CeeeWindowHandle handle = reinterpret_cast<CeeeWindowHandle>(tab_window_); | 1579 HRESULT hr = FireMapToolbandIdToHandle(session_id); |
| 1569 HRESULT hr = SetTabToolBandIdForHandle(session_id, handle); | |
| 1570 if (FAILED(hr)) { | 1580 if (FAILED(hr)) { |
| 1571 DCHECK(SUCCEEDED(hr)) << "An error occured when setting the toolband " << | 1581 DCHECK(SUCCEEDED(hr)) << "An error occured when setting the toolband " << |
| 1572 "tab ID: " << com::LogHr(hr); | 1582 "tab ID: " << com::LogHr(hr); |
| 1573 return hr; | 1583 return hr; |
| 1574 } | 1584 } |
| 1575 VLOG(2) << "ToolBandTabId(" << session_id << ") set for Handle(" << handle << | 1585 VLOG(2) << "ToolBandTabId(" << session_id << ") set for Handle(" << |
| 1576 ")"; | 1586 tab_window_ << ")"; |
| 1577 return hr; | 1587 return hr; |
| 1578 } | 1588 } |
| 1579 | 1589 |
| 1580 HRESULT BrowserHelperObject::SendEventToBroker(const char* event_name, | 1590 HRESULT BrowserHelperObject::SendEventToBroker(const char* event_name, |
| 1581 const char* event_args) { | 1591 const char* event_args) { |
| 1582 if (EnsureTabId() == false) { | 1592 if (EnsureTabId() == false) { |
| 1583 deferred_events_call_.push_back(NewRunnableMethod( | 1593 deferred_events_call_.push_back(NewRunnableMethod( |
| 1584 this, &BrowserHelperObject::SendEventToBrokerImpl, | 1594 this, &BrowserHelperObject::SendEventToBrokerImpl, |
| 1585 std::string(event_name), std::string(event_args))); | 1595 std::string(event_name), std::string(event_args))); |
| 1586 VLOG(2) << "Deferred SendEventToBroker. Name: \"" << event_name << | 1596 VLOG(2) << "Deferred SendEventToBroker. Name: \"" << event_name << |
| 1587 "\", args: \"" << event_args << "\"."; | 1597 "\", args: \"" << event_args << "\"."; |
| 1588 return S_FALSE; | 1598 return S_FALSE; |
| 1589 } else { | 1599 } else { |
| 1590 return SendEventToBrokerImpl(event_name, event_args); | 1600 return SendEventToBrokerImpl(event_name, event_args); |
| 1591 } | 1601 } |
| 1592 } | 1602 } |
| 1593 | 1603 |
| 1594 HRESULT BrowserHelperObject::SendEventToBrokerImpl( | 1604 HRESULT BrowserHelperObject::SendEventToBrokerImpl( |
| 1595 const std::string& event_name, const std::string& event_args) { | 1605 const std::string& event_name, const std::string& event_args) { |
| 1596 return broker_rpc().FireEvent(event_name.c_str(), event_args.c_str()); | 1606 return broker_rpc().FireEvent(event_name.c_str(), event_args.c_str()); |
| 1597 } | 1607 } |
| OLD | NEW |