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