OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/browser/chromeos/arc/arc_intent_helper_bridge_impl.h" | 5 #include "chrome/browser/chromeos/arc/arc_intent_helper_bridge_impl.h" |
6 | 6 |
| 7 #include "base/json/json_writer.h" |
7 #include "chrome/browser/profiles/profile_manager.h" | 8 #include "chrome/browser/profiles/profile_manager.h" |
8 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" | 9 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" |
9 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
10 #include "chrome/browser/ui/browser_tabstrip.h" | 11 #include "chrome/browser/ui/browser_tabstrip.h" |
11 #include "chrome/browser/ui/browser_window.h" | 12 #include "chrome/browser/ui/browser_window.h" |
12 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" | 13 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" |
13 #include "components/arc/common/intent_helper.mojom.h" | 14 #include "components/arc/common/intent_helper.mojom.h" |
14 | 15 |
15 namespace arc { | 16 namespace arc { |
16 | 17 |
17 ArcIntentHelperBridgeImpl::ArcIntentHelperBridgeImpl() : binding_(this) {} | 18 ArcIntentHelperBridgeImpl::ArcIntentHelperBridgeImpl() : binding_(this) {} |
18 | 19 |
19 ArcIntentHelperBridgeImpl::~ArcIntentHelperBridgeImpl() { | 20 ArcIntentHelperBridgeImpl::~ArcIntentHelperBridgeImpl() { |
20 ArcBridgeService* bridge_service = ArcBridgeService::Get(); | 21 ArcBridgeService* bridge_service = ArcBridgeService::Get(); |
21 DCHECK(bridge_service); | 22 DCHECK(bridge_service); |
22 bridge_service->RemoveObserver(this); | 23 bridge_service->RemoveObserver(this); |
23 } | 24 } |
24 | 25 |
25 void ArcIntentHelperBridgeImpl::StartObservingBridgeServiceChanges() { | 26 void ArcIntentHelperBridgeImpl::StartObservingBridgeServiceChanges() { |
26 ArcBridgeService* bridge_service = ArcBridgeService::Get(); | 27 ArcBridgeService* bridge_service = ArcBridgeService::Get(); |
27 DCHECK(bridge_service); | 28 DCHECK(bridge_service); |
28 bridge_service->AddObserver(this); | 29 bridge_service->AddObserver(this); |
29 } | 30 } |
30 | 31 |
| 32 void ArcIntentHelperBridgeImpl::OnStateChanged(ArcBridgeService::State state) { |
| 33 // ArcBridgeService::State::READY is emitted before ArcIntentHelper app is |
| 34 // ready to send broadcasts. Instead we wait for the IntentHelperInstance |
| 35 // to be ready. |
| 36 if (state == ArcBridgeService::State::STOPPING) { |
| 37 settings_bridge_.reset(); |
| 38 } |
| 39 } |
| 40 |
31 void ArcIntentHelperBridgeImpl::OnIntentHelperInstanceReady() { | 41 void ArcIntentHelperBridgeImpl::OnIntentHelperInstanceReady() { |
32 IntentHelperHostPtr host; | 42 IntentHelperHostPtr host; |
33 binding_.Bind(mojo::GetProxy(&host)); | 43 binding_.Bind(mojo::GetProxy(&host)); |
34 ArcBridgeService* bridge_service = ArcBridgeService::Get(); | 44 ArcBridgeService* bridge_service = ArcBridgeService::Get(); |
35 bridge_service->intent_helper_instance()->Init(std::move(host)); | 45 bridge_service->intent_helper_instance()->Init(std::move(host)); |
| 46 settings_bridge_.reset(new SettingsBridge(this)); |
36 } | 47 } |
37 | 48 |
38 void ArcIntentHelperBridgeImpl::OnOpenUrl(const mojo::String& url) { | 49 void ArcIntentHelperBridgeImpl::OnOpenUrl(const mojo::String& url) { |
39 GURL gurl(url.get()); | 50 GURL gurl(url.get()); |
40 if (!gurl.is_valid()) | 51 if (!gurl.is_valid()) |
41 return; | 52 return; |
42 | 53 |
43 chrome::ScopedTabbedBrowserDisplayer displayer( | 54 chrome::ScopedTabbedBrowserDisplayer displayer( |
44 ProfileManager::GetActiveUserProfile(), chrome::HOST_DESKTOP_TYPE_ASH); | 55 ProfileManager::GetActiveUserProfile(), chrome::HOST_DESKTOP_TYPE_ASH); |
45 chrome::AddSelectedTabWithURL(displayer.browser(), gurl, | 56 chrome::AddSelectedTabWithURL(displayer.browser(), gurl, |
46 ui::PAGE_TRANSITION_LINK); | 57 ui::PAGE_TRANSITION_LINK); |
47 | 58 |
48 // Since the ScopedTabbedBrowserDisplayer does not guarantee that the | 59 // Since the ScopedTabbedBrowserDisplayer does not guarantee that the |
49 // browser will be shown on the active desktop, we ensure the visibility. | 60 // browser will be shown on the active desktop, we ensure the visibility. |
50 multi_user_util::MoveWindowToCurrentDesktop( | 61 multi_user_util::MoveWindowToCurrentDesktop( |
51 displayer.browser()->window()->GetNativeWindow()); | 62 displayer.browser()->window()->GetNativeWindow()); |
52 } | 63 } |
53 | 64 |
| 65 void ArcIntentHelperBridgeImpl::OnBroadcastNeeded( |
| 66 const std::string& action, |
| 67 const base::DictionaryValue& extras) { |
| 68 ArcBridgeService* bridge_service = ArcBridgeService::Get(); |
| 69 if (!bridge_service || |
| 70 bridge_service->state() != ArcBridgeService::State::READY) { |
| 71 LOG(ERROR) << "Bridge service is not ready."; |
| 72 return; |
| 73 } |
| 74 |
| 75 std::string extras_json; |
| 76 bool write_success = base::JSONWriter::Write(extras, &extras_json); |
| 77 DCHECK(write_success); |
| 78 bridge_service->intent_helper_instance()->SendBroadcast( |
| 79 action, "org.chromium.arc.intent_helper", |
| 80 "org.chromium.arc.intent_helper.SettingsReceiver", extras_json); |
| 81 } |
| 82 |
54 } // namespace arc | 83 } // namespace arc |
OLD | NEW |