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.h" | 5 #include "chrome/browser/chromeos/arc/arc_intent_helper_bridge.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 ArcIntentHelperBridge::ArcIntentHelperBridge(ArcBridgeService* bridge_service) | 18 ArcIntentHelperBridge::ArcIntentHelperBridge(ArcBridgeService* bridge_service) |
18 : ArcService(bridge_service), binding_(this) { | 19 : ArcService(bridge_service), binding_(this) { |
19 arc_bridge_service()->AddObserver(this); | 20 arc_bridge_service()->AddObserver(this); |
20 } | 21 } |
21 | 22 |
22 ArcIntentHelperBridge::~ArcIntentHelperBridge() { | 23 ArcIntentHelperBridge::~ArcIntentHelperBridge() { |
23 arc_bridge_service()->RemoveObserver(this); | 24 arc_bridge_service()->RemoveObserver(this); |
24 } | 25 } |
25 | 26 |
26 void ArcIntentHelperBridge::OnIntentHelperInstanceReady() { | 27 void ArcIntentHelperBridge::OnIntentHelperInstanceReady() { |
27 IntentHelperHostPtr host; | 28 IntentHelperHostPtr host; |
28 binding_.Bind(mojo::GetProxy(&host)); | 29 binding_.Bind(mojo::GetProxy(&host)); |
29 arc_bridge_service()->intent_helper_instance()->Init(std::move(host)); | 30 arc_bridge_service()->intent_helper_instance()->Init(std::move(host)); |
| 31 settings_bridge_.reset(new SettingsBridge(this)); |
| 32 } |
| 33 |
| 34 void ArcIntentHelperBridge::OnIntentHelperInstanceClosed() { |
| 35 settings_bridge_.reset(); |
30 } | 36 } |
31 | 37 |
32 void ArcIntentHelperBridge::OnOpenUrl(const mojo::String& url) { | 38 void ArcIntentHelperBridge::OnOpenUrl(const mojo::String& url) { |
33 GURL gurl(url.get()); | 39 GURL gurl(url.get()); |
34 if (!gurl.is_valid()) | 40 if (!gurl.is_valid()) |
35 return; | 41 return; |
36 | 42 |
37 chrome::ScopedTabbedBrowserDisplayer displayer( | 43 chrome::ScopedTabbedBrowserDisplayer displayer( |
38 ProfileManager::GetActiveUserProfile(), chrome::HOST_DESKTOP_TYPE_ASH); | 44 ProfileManager::GetActiveUserProfile(), chrome::HOST_DESKTOP_TYPE_ASH); |
39 chrome::AddSelectedTabWithURL(displayer.browser(), gurl, | 45 chrome::AddSelectedTabWithURL(displayer.browser(), gurl, |
40 ui::PAGE_TRANSITION_LINK); | 46 ui::PAGE_TRANSITION_LINK); |
41 | 47 |
42 // Since the ScopedTabbedBrowserDisplayer does not guarantee that the | 48 // Since the ScopedTabbedBrowserDisplayer does not guarantee that the |
43 // browser will be shown on the active desktop, we ensure the visibility. | 49 // browser will be shown on the active desktop, we ensure the visibility. |
44 multi_user_util::MoveWindowToCurrentDesktop( | 50 multi_user_util::MoveWindowToCurrentDesktop( |
45 displayer.browser()->window()->GetNativeWindow()); | 51 displayer.browser()->window()->GetNativeWindow()); |
46 } | 52 } |
47 | 53 |
| 54 void ArcIntentHelperBridge::OnBroadcastNeeded( |
| 55 const std::string& action, |
| 56 const base::DictionaryValue& extras) { |
| 57 if (arc_bridge_service()->state() != ArcBridgeService::State::READY) { |
| 58 LOG(ERROR) << "Bridge service is not ready."; |
| 59 return; |
| 60 } |
| 61 |
| 62 std::string extras_json; |
| 63 bool write_success = base::JSONWriter::Write(extras, &extras_json); |
| 64 DCHECK(write_success); |
| 65 |
| 66 if (arc_bridge_service()->intent_helper_version() >= 1) { |
| 67 arc_bridge_service()->intent_helper_instance()->SendBroadcast( |
| 68 action, "org.chromium.arc.intent_helper", |
| 69 "org.chromium.arc.intent_helper.SettingsReceiver", extras_json); |
| 70 } |
| 71 } |
| 72 |
48 } // namespace arc | 73 } // namespace arc |
OLD | NEW |