| 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 "ash/shell.h" |
| 7 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
| 8 #include "chrome/browser/profiles/profile_manager.h" | 9 #include "chrome/browser/profiles/profile_manager.h" |
| 9 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" | 10 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" |
| 10 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
| 11 #include "chrome/browser/ui/browser_tabstrip.h" | 12 #include "chrome/browser/ui/browser_tabstrip.h" |
| 12 #include "chrome/browser/ui/browser_window.h" | 13 #include "chrome/browser/ui/browser_window.h" |
| 13 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" | 14 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" |
| 14 #include "components/arc/common/intent_helper.mojom.h" | 15 #include "components/arc/common/intent_helper.mojom.h" |
| 15 | 16 |
| 16 namespace arc { | 17 namespace arc { |
| 17 | 18 |
| 18 ArcIntentHelperBridge::ArcIntentHelperBridge(ArcBridgeService* bridge_service) | 19 ArcIntentHelperBridge::ArcIntentHelperBridge(ArcBridgeService* bridge_service) |
| 19 : ArcService(bridge_service), binding_(this) { | 20 : ArcService(bridge_service), binding_(this) { |
| 20 arc_bridge_service()->AddObserver(this); | 21 arc_bridge_service()->AddObserver(this); |
| 21 } | 22 } |
| 22 | 23 |
| 23 ArcIntentHelperBridge::~ArcIntentHelperBridge() { | 24 ArcIntentHelperBridge::~ArcIntentHelperBridge() { |
| 24 arc_bridge_service()->RemoveObserver(this); | 25 arc_bridge_service()->RemoveObserver(this); |
| 25 } | 26 } |
| 26 | 27 |
| 27 void ArcIntentHelperBridge::OnIntentHelperInstanceReady() { | 28 void ArcIntentHelperBridge::OnIntentHelperInstanceReady() { |
| 28 arc_bridge_service()->intent_helper_instance()->Init( | 29 arc_bridge_service()->intent_helper_instance()->Init( |
| 29 binding_.CreateInterfacePtrAndBind()); | 30 binding_.CreateInterfacePtrAndBind()); |
| 30 settings_bridge_.reset(new SettingsBridge(this)); | 31 settings_bridge_.reset(new SettingsBridge(this)); |
| 32 ash::Shell::GetInstance()->open_with_menu_controller()->SetDelegate(this); |
| 31 } | 33 } |
| 32 | 34 |
| 33 void ArcIntentHelperBridge::OnIntentHelperInstanceClosed() { | 35 void ArcIntentHelperBridge::OnIntentHelperInstanceClosed() { |
| 36 ash::Shell::GetInstance()->open_with_menu_controller()->SetDelegate(NULL); |
| 34 settings_bridge_.reset(); | 37 settings_bridge_.reset(); |
| 35 } | 38 } |
| 36 | 39 |
| 37 void ArcIntentHelperBridge::OnOpenUrl(const mojo::String& url) { | 40 void ArcIntentHelperBridge::OnOpenUrl(const mojo::String& url) { |
| 38 GURL gurl(url.get()); | 41 GURL gurl(url.get()); |
| 39 if (!gurl.is_valid()) | 42 if (!gurl.is_valid()) |
| 40 return; | 43 return; |
| 41 | 44 |
| 42 chrome::ScopedTabbedBrowserDisplayer displayer( | 45 chrome::ScopedTabbedBrowserDisplayer displayer( |
| 43 ProfileManager::GetActiveUserProfile()); | 46 ProfileManager::GetActiveUserProfile()); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 62 bool write_success = base::JSONWriter::Write(extras, &extras_json); | 65 bool write_success = base::JSONWriter::Write(extras, &extras_json); |
| 63 DCHECK(write_success); | 66 DCHECK(write_success); |
| 64 | 67 |
| 65 if (arc_bridge_service()->intent_helper_version() >= 1) { | 68 if (arc_bridge_service()->intent_helper_version() >= 1) { |
| 66 arc_bridge_service()->intent_helper_instance()->SendBroadcast( | 69 arc_bridge_service()->intent_helper_instance()->SendBroadcast( |
| 67 action, "org.chromium.arc.intent_helper", | 70 action, "org.chromium.arc.intent_helper", |
| 68 "org.chromium.arc.intent_helper.SettingsReceiver", extras_json); | 71 "org.chromium.arc.intent_helper.SettingsReceiver", extras_json); |
| 69 } | 72 } |
| 70 } | 73 } |
| 71 | 74 |
| 75 int ArcIntentHelperBridge::PopulateOpenWithMenu( |
| 76 RenderViewContextMenuProxy* proxy, |
| 77 int menu_id_start, |
| 78 size_t num_menu_items, |
| 79 const GURL& url) { |
| 80 menu_delegate_impl_.reset( |
| 81 new OpenWithMenuControllerDelegate(arc_bridge_service())); |
| 82 return menu_delegate_impl_->Init(proxy, menu_id_start, num_menu_items, url); |
| 83 } |
| 84 |
| 85 void ArcIntentHelperBridge::ExecuteCommand(int id) { |
| 86 if (!menu_delegate_impl_) |
| 87 return; |
| 88 menu_delegate_impl_->ExecuteCommand(id); |
| 89 } |
| 90 |
| 91 void ArcIntentHelperBridge::MenuClosed() { |
| 92 menu_delegate_impl_.reset(); |
| 93 } |
| 94 |
| 72 } // namespace arc | 95 } // namespace arc |
| OLD | NEW |